Last active
December 24, 2015 04:49
-
-
Save guilhermesilveira/6746076 to your computer and use it in GitHub Desktop.
custom serialization
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 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)); | |
} | |
} |
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 IncludeOption extends Option { | |
private String fields; | |
IncludeOption(String... fields) { | |
this.fields = fields; | |
} | |
public XStream apply(XStream serializer) { | |
} | |
public GSon apply(GSon serializer) { | |
} | |
} |
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 LinkConverter { | |
public Option linkFor(Class type) { | |
String controller = Class.forName(type.getName + "Controller"); | |
return x; // new Option that registers the converter to controller.show(); | |
} | |
} |
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 interface Option { | |
public XStream apply(XStream serializer) ; | |
public GSon apply(GSon serializer) ; | |
} |
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 SerializationConfig { | |
SerializationConfig with(Option<T>... option); | |
} |
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 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