Created
November 21, 2014 21:39
-
-
Save Shujito/d04f1bba3c65df87dc3f to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Estrategia de exclusion para {@link Gson} para saltarse campos que no sean serializables | |
* @author shujito | |
*/ | |
public class ExcludeFieldsWithoutSerializedName implements ExclusionStrategy | |
{ | |
@Override | |
public boolean shouldSkipClass(Class<?> clss) | |
{ | |
return false; | |
} | |
@Override | |
public boolean shouldSkipField(FieldAttributes fieldAttributes) | |
{ | |
// get all annotations, skip these without @SerializedName | |
Collection<Annotation> annotations = fieldAttributes.getAnnotations(); | |
for (Annotation a : annotations) | |
{ | |
if (a instanceof SerializedName) | |
{ | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
This file contains 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
public class SomeApplication | |
{ | |
/* ... app code ... */ | |
@Override | |
public void onCreate() | |
{ | |
super.onCreate(); | |
Log.e(TAG, "Force log to cat"); | |
instance = this; | |
Configuration configuration = new Configuration.Builder(this) | |
.setDatabaseName(this.getPackageName()) | |
.setDatabaseVersion(1) | |
.create(); | |
ActiveAndroid.initialize(configuration); | |
ExcludeFieldsWithoutSerializedName efwosn = new ExcludeFieldsWithoutSerializedName(); | |
Ion.getDefault(this) | |
.configure() | |
.setGson(new GsonBuilder() | |
.addDeserializationExclusionStrategy(efwosn) | |
.addSerializationExclusionStrategy(efwosn) | |
.create()); | |
} | |
/* ... app code ... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment