Created
November 19, 2015 15:35
-
-
Save kamilZ/1aa94610a3263703a33f to your computer and use it in GitHub Desktop.
Gson util class when you using gson with realm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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