Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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;
}
}
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
You can’t perform that action at this time.