I see that Jackson (com.fasterxml.jackson) allows me to use mixin annotations to alter JSON/XML attributes when marshalling from a POJO. For instance, granted I've got the following Track class...
public class Track {
private String title = "";
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
...i can simply add a mixin class...
public abstract class MixInTrack {
@JsonProperty("theTitle") abstract String getTitle();
}
...and then title gets written as theTitle...
<Track>
<theTitle>Warm Memories</theTitle>
</Track>
Now, to get up and running with mixin annotations, I need to extend com.fasterxml.jackson.databind.module.SimpleModule :
public class DefaultModule extends SimpleModule {
public DefaultModule() {
super("marshaller", new Version(0, 0, 1, null, "com.company", "marshaller"));
}
@Override
public void setupModule(SetupContext context) {
context.setMixInAnnotations(Track.class, MixInTrack.class);
}
}
My question : can I somehow use Version (see constructor of DefaultModule) to control how Jackson outputs my XML? I'd like to have the opportunity to control the XML that gets generated based on a version. As an extension to this question, can I somehow also use Jackson to control which XML properties get written and which get ignored if I have an authentication scheme where users have access to different data?
No comments:
Post a Comment