Reads JsonObject
s through constructors using Gson. Example:
class User @Read constructor(
@ReadAs("firstName") val name: String,
@ReadAs("lastName") val surname: String
)
val gson = GsonBuilder()
.registerTypeAdapterFactory(ConstructorTypeAdapterFactory)
.create()
val user = gson.fromJson<User>("""{
"firstName": "Mike",
"lastName": "G"
}""", User::class.java)
Changelog
-
1.0
- Init. Using @Read, @Write, @ReadAs, @WriteAs
-
1.2
- Supporting
@ReadAsRoot
and@MergeWithRoot
, see ReadAsRootTest for sample usage
- Supporting
-
1.2.1
- Fixed null-value parsing
-
1.2.2
- Fixed generic type parsing