Creates objects in normal way — through constructors.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.idea
gradle/wrapper
src
.gitignore
build.gradle
gradlew
gradlew.bat
license
readme.md
settings.gradle

readme.md

Reads JsonObjects 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)

Show me the code

Changelog

  • 1.0

    • Init. Using @Read, @Write, @ReadAs, @WriteAs
  • 1.2

    • Supporting @ReadAsRoot and @MergeWithRoot, see ReadAsRootTest for sample usage
  • 1.2.1

    • Fixed null-value parsing
  • 1.2.2

    • Fixed generic type parsing