Skip to content

Instantly share code, notes, and snippets.

@jocollet
jocollet / RealmGsonParsing.java
Last active April 12, 2016 09:53
Example of TypeAdapters to convert json to Realm objects
// ref : https://gist.github.com/cmelchior/1a97377df0c49cd4fca9
private void initGson() {
Type tokenInt = new TypeToken<RealmList<RealmInt>>(){}.getType();
Type tokenString = new TypeToken<RealmList<RealmString>>(){}.getType();
Type tokenDate = new TypeToken<Date>(){}.getType();
mGson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.ssssss")
.setExclusionStrategies(new ExclusionStrategy() {
@Override