Skip to content

Instantly share code, notes, and snippets.

@kamilZ
Created November 19, 2015 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamilZ/1aa94610a3263703a33f to your computer and use it in GitHub Desktop.
Save kamilZ/1aa94610a3263703a33f to your computer and use it in GitHub Desktop.
Gson util class when you using gson with realm
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.realm.RealmObject;
public class GsonUtil {
public static Gson getInstance(){
return new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment