kotlin-client.jvm-common.infrastructure.URIAdapter.kt.mustache Maven / Gradle / Ivy
The newest version!
package {{packageName}}.infrastructure
{{#kotlinx_serialization}}
import kotlinx.serialization.KSerializer
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.SerialDescriptor
{{/kotlinx_serialization}}
{{#moshi}}
import com.squareup.moshi.FromJson
import com.squareup.moshi.ToJson
{{/moshi}}
import java.net.URI
{{#moshi}}
{{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}class URIAdapter {
@ToJson
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}fun toJson(uri: URI): String = uri.toString()
@FromJson
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}fun fromJson(s: String): URI = URI.create(s)
}
{{/moshi}}
{{#kotlinx_serialization}}
{{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}object URIAdapter : KSerializer {
override fun serialize(encoder: Encoder, value: URI) {
encoder.encodeString(value.toASCIIString())
}
override fun deserialize(decoder: Decoder): URI = URI(decoder.decodeString())
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("URI", PrimitiveKind.STRING)
}
{{/kotlinx_serialization}}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy