rharter / auto-gson
posted
Category: Other
Minimum SDK Level: Unknown :(

Badge

View in Github Github project information
Starred: 383
Forks: 45
Watchers: 23
Open Issues: 20

Snapshot pictures

No snapshot for this library yet.

Description

AutoGson

An extension for Google's AutoValue that creates a simple Gson Serializer and Deserializer for each AutoValue annotated object.

Note: This is a very early version that won't work with the released AutoValue until a PR has been merged.

Usage

Simply include AutoGson in your project and add the generated Serializer and Deserializer as a TypeAdapter. You can also annotate your properties using @SerializedName to define an alternate name for de/serialization.

@AutoValue public abstract class Foo {
  abstract String bar();
  @SerializedName("Baz") abstract String baz();
}

final Gson gson = new GsonBuilder()
  .registerTypeAdapterFactory(Foo.class, AutoValue_Foo.typeAdapterFactory())
  .create();

Now build your project and de/serialize your Foo.

2

See also