kotlin-client.jvm-common.infrastructure.LocalTimeAdapter.kt.mustache Maven / Gradle / Ivy
package {{packageName}}.infrastructure
{{#moshi}}
import com.squareup.moshi.FromJson
import com.squareup.moshi.ToJson
{{/moshi}}
{{#gson}}
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import com.google.gson.stream.JsonToken.NULL
import java.io.IOException
{{/gson}}
import kotlinx.datetime.LocalTime
{{#moshi}}
{{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}class LocalTimeAdapter {
@ToJson
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}fun toJson(value: LocalTime): String {
return value.toString()
}
@FromJson
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}fun fromJson(value: String): LocalTime {
return LocalTime.parse(value)
}
}
{{/moshi}}
{{#gson}}
{{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}class LocalTimeAdapter : TypeAdapter() {
@Throws(IOException::class)
override fun write(out: JsonWriter?, value: LocalTime?) {
if (value == null) {
out?.nullValue()
} else {
out?.value(value.toString())
}
}
@Throws(IOException::class)
override fun read(out: JsonReader?): LocalTime? {
out ?: return null
when (out.peek()) {
NULL -> {
out.nextNull()
return null
}
else -> {
return LocalTime.parse(out.nextString())
}
}
}
}
{{/gson}}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy