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);
http://immutables.github.io/immutable.html
-
elucash for all the support for Android on Immutables
-
saulmm and gabrielemariotti for build.gradle configuration
-
https://gist.github.com/gabrielemariotti/ad6672902464ee2392d0
-
frogermcs for over 65k limit tutorial
-
http://frogermcs.github.io/MultiDex-solution-for-64k-limit-in-Dalvik/