How to map POJO to several JSON presentation?
I am using Jackson.
I want something like code below
@JsonIgnorePropertiesStreamA({ \"value2\"
You use JSON Views
class Views {
static class PublicView { }
static class StreamA extends PublicView { }
static class OtherWay extends PublicView { }
}
public class Value {
@JsonView(Views.PublicView.class) public int value;
@JsonView(Views.OtherWay.class) public int value2;
@JsonView(Views.StreamA.class) public int value3;
}
String json = new ObjectMapper()
.writerWithView(Views.OtherWay.class)
.writeValueAsString(valueInstance);
Note that these are inclusive rather than exclusive; you create a view that includes the fields you want.