Moshi is a modern JSON library for Kotlin and Java, This is a extension library of Moshi just for Kotlin.
- open the
build.gradle
file in project root path and write down the codes of below
allprojects {
repositories {
maven { url 'https://dl.bintray.com/badboy/lib' }
}
}
- open the
build.gradle
file inapp
path
implementation 'com.badboy.lib:moshix:1.0.0'
- For other usage, please refer to __Moshi Official Github Page __
data class Person(val name: String = "zhongzilu")
val jsonString = Person().toJson()
println(jsonString)
output:
{"name":"zhongzilu"}
val json = "{\"name\":\"badboy\"}"
val person = Json.convert2<Person>(json)
println(person.toString())
output:
Person(name=badboy)
val builder = Json.builder.add(CustomJsonAdapterFactory())
val moshi = builder.build()
val person = moshi.adapter(Person::class.java).fromJson("")
or
Json.builder.add(CustomJsonAdapterFactory())
val person = Json.convert2<Person>("")