All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.gesellix.docker.compose.adapters.ListToExposeAdapter.kt Maven / Gradle / Ivy

package de.gesellix.docker.compose.adapters

import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonReader
import com.squareup.moshi.ToJson
import de.gesellix.docker.compose.types.Exposes

class ListToExposeAdapter {

    @ToJson
    fun toJson(@ExposesType exposes: Exposes): List {
        throw UnsupportedOperationException()
    }

    @FromJson
    @ExposesType
    fun fromJson(reader: JsonReader): Exposes {
        val exposes = Exposes()
        when (reader.peek()) {
            JsonReader.Token.BEGIN_ARRAY -> {
                reader.beginArray()
                while (reader.hasNext()) {
                    if (reader.peek() == JsonReader.Token.NUMBER) {
                        exposes.entries.add(reader.nextInt().toString())
                    } else {
                        exposes.entries.add(reader.nextString())
                    }
                }
                reader.endArray()
            }
            else -> {
                // ...
            }
        }
        return exposes
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy