Skip to content

Instantly share code, notes, and snippets.

@SeongUgJung
Last active February 20, 2021 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeongUgJung/6297162e95670f777c98e6df47aac476 to your computer and use it in GitHub Desktop.
Save SeongUgJung/6297162e95670f777c98e6df47aac476 to your computer and use it in GitHub Desktop.
// this will generate PersonAdapter.kt
@JsonClass(generateAdapter = true)
data class Person(
val name: String,
val age: Int,
val phone: Phone
)
class PersonAdapterFactory : JsonAdapter.Factory {
overridee fun create(type: Type, moshi: Moshi) =
if (type == Person::class.java) PersonAdapter(moshi) else null
}
// this will generate PhoneAdapter.kt
@JsonClass(generateAdapter = true)
data class Phone(
val mobile: String,
val home: String,
val office: String
)
class PhoneAdapterFactory : JsonAdapter.Factory {
overridee fun create(type: Type, moshi: Moshi) =
if (type == Phone::class.java) PhoneAdapter(moshi) else null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment