Skip to content

Miha-x64/gson-constructor-type-adapter-factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Creates objects in normal way — through constructors.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages