[kotlin][client] make serializer configurable (#4740)

* [kotlin][client] make serializer configurable

* [kotlin] update pet projects
This commit is contained in:
Bruno Coelho 2019-12-20 10:08:16 +00:00 committed by William Cheng
parent b6fd1b0ade
commit 9feaae8572
9 changed files with 60 additions and 20 deletions

View File

@ -25,7 +25,7 @@ import java.util.Date
{{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer {
{{#moshi}}
@JvmStatic
val moshi: Moshi = Moshi.Builder()
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
@ -34,16 +34,24 @@ import java.util.Date
{{^moshiCodeGen}}
.add(KotlinJsonAdapterFactory())
{{/moshiCodeGen}}
.build()
@JvmStatic
val moshi: Moshi by lazy {
moshiBuilder.build()
}
{{/moshi}}
{{#gson}}
@JvmStatic
val gson: Gson = GsonBuilder()
val gsonBuilder: GsonBuilder = GsonBuilder()
.registerTypeAdapter(Date::class.java, DateAdapter())
.registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter())
.registerTypeAdapter(LocalDate::class.java, LocalDateAdapter())
.registerTypeAdapter(UUID::class.java, UUIDAdapter())
.registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter())
.create()
@JvmStatic
val gson: Gson by lazy {
gsonBuilder.create()
}
{{/gson}}
}

View File

@ -9,11 +9,15 @@ import java.util.Date
object Serializer {
@JvmStatic
val gson: Gson = GsonBuilder()
val gsonBuilder: GsonBuilder = GsonBuilder()
.registerTypeAdapter(Date::class.java, DateAdapter())
.registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter())
.registerTypeAdapter(LocalDate::class.java, LocalDateAdapter())
.registerTypeAdapter(UUID::class.java, UUIDAdapter())
.registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter())
.create()
@JvmStatic
val gson: Gson by lazy {
gsonBuilder.create()
}
}

View File

@ -6,11 +6,15 @@ import java.util.Date
object Serializer {
@JvmStatic
val moshi: Moshi = Moshi.Builder()
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.build()
@JvmStatic
val moshi: Moshi by lazy {
moshiBuilder.build()
}
}

View File

@ -7,12 +7,16 @@ import java.util.Date
internal object Serializer {
@JvmStatic
val moshi: Moshi = Moshi.Builder()
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build()
@JvmStatic
val moshi: Moshi by lazy {
moshiBuilder.build()
}
}

View File

@ -7,12 +7,16 @@ import java.util.Date
object Serializer {
@JvmStatic
val moshi: Moshi = Moshi.Builder()
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build()
@JvmStatic
val moshi: Moshi by lazy {
moshiBuilder.build()
}
}

View File

@ -7,12 +7,16 @@ import java.util.Date
object Serializer {
@JvmStatic
val moshi: Moshi = Moshi.Builder()
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build()
@JvmStatic
val moshi: Moshi by lazy {
moshiBuilder.build()
}
}

View File

@ -7,12 +7,16 @@ import java.util.Date
object Serializer {
@JvmStatic
val moshi: Moshi = Moshi.Builder()
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build()
@JvmStatic
val moshi: Moshi by lazy {
moshiBuilder.build()
}
}

View File

@ -7,12 +7,16 @@ import java.util.Date
object Serializer {
@JvmStatic
val moshi: Moshi = Moshi.Builder()
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build()
@JvmStatic
val moshi: Moshi by lazy {
moshiBuilder.build()
}
}

View File

@ -7,12 +7,16 @@ import java.util.Date
object Serializer {
@JvmStatic
val moshi: Moshi = Moshi.Builder()
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build()
@JvmStatic
val moshi: Moshi by lazy {
moshiBuilder.build()
}
}