Skip to content

Instantly share code, notes, and snippets.

@guilhermesilveira
Last active December 24, 2015 04:49
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 guilhermesilveira/6746076 to your computer and use it in GitHub Desktop.
Save guilhermesilveira/6746076 to your computer and use it in GitHub Desktop.
custom serialization
public class Controller {
public void x() {
// custom whatever
result.from(object).with(new RafaelRuleOfNonArrayReplicationInJson());
// music include
result.from(object).with(include("musica"));
// with link
result.from(object).with(linkFor(Musica.class));
}
}
public class IncludeOption extends Option {
private String fields;
IncludeOption(String... fields) {
this.fields = fields;
}
public XStream apply(XStream serializer) {
}
public GSon apply(GSon serializer) {
}
}
public class LinkConverter {
public Option linkFor(Class type) {
String controller = Class.forName(type.getName + "Controller");
return x; // new Option that registers the converter to controller.show();
}
}
public interface Option {
public XStream apply(XStream serializer) ;
public GSon apply(GSon serializer) ;
}
public class SerializationConfig {
SerializationConfig with(Option<T>... option);
}
public class StaticCustom {
public static Option include(String... fieldNames) {
return IncludeOption(fieldNames);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment