Assume that your POJO
class looks like this:
class PojoA {
private String b;
// getters, setters
}
Now, you have to create MixIn interface:
interface PojoAMixIn {
@JsonProperty("newB")
String getB();
}
Simple usage:
PojoA pojoA = new PojoA();
pojoA.setB("B value");
System.out.println("Without MixIn:");
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(pojoA));
System.out.println("With MixIn:");
ObjectMapper mapperWithMixIn = new ObjectMapper();
mapperWithMixIn.addMixInAnnotations(PojoA.class, PojoAMixIn.class);
System.out.println(mapperWithMixIn.writerWithDefaultPrettyPrinter().writeValueAsString(pojoA));
Above program prints:
Without MixIn:
{
"b" : "B value"
}
With MixIn:
{
"newB" : "B value"
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…