I have multiple classes and for all of them I don't want id field to be the part of my output JSON string (serialization). Let say I have 2 classes
@JsonIgnoreProperties(value = { "id" })
public final class Person {
private ObjectId id;
//........
}
@JsonIgnoreProperties(value = { "id" })
public final class Address{
private ObjectId id;
//........
}
Now I don't want to specify @JsonIgnoreProperties(value = { "id" })
manually on all my 1000 classes. Is there any global way to do, so that I can apply this part for all my classes? Very similarly like mapper.setSerializationInclusion(Include.NON_NULL)
in below method?
public String serialize(T dataObject) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
String result = mapper.writeValueAsString(dataObject);
return result;
}
One way I tried is to make a super class and applied @JsonIgnoreProperties on top of that (which works). But still I have to write "extends" in every child class which I don't prefer. Is there any way in which I can apply this setting without adding anything additional in my pojo class?