/Immutables-Android-Example

Example of use Immutables 2.0 fro Android and GSON

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Immutables Android Example

Small example of use Immutables 2.0 for Android and GSON. You can also follow the Android start guide of Immutables

With the follow User model:

@Gson.TypeAdapters
@Value.Immutable
public abstract class User {

    public abstract int id();

    public abstract String username();
}

We can use it as:

User user = ImmutableUser.builder().id(1).username("olidroide").build();

Serialize:

String jsonUser = new JsonFromUser().map(user);

Deserialize:

User user = new UserFromJson().map(jsonUser);

More info

http://immutables.github.io/immutable.html

Thanks to