toJson
open override fun toJson( writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: Optional.Present<T>)
Content copied to clipboard
Serializes a Kotlin type into its equivalent Json representation.
Example:
override fun toJson(writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: Hero) {
writer.name("name")
writer.value(value.name)
writer.name("homeworld")
writer.value(value.homeworld)
}
Content copied to clipboard
Alternatively, you can use the built-in AnyAdapter:
override fun toJson(writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: Hero) {
val map = mapOf("name" to value.name, "homeworld" to value.homeworld)
AnyAdapter.toJson(writer, customScalarAdapters, map)
}
Content copied to clipboard