I have ObjectMapper instance:
ObjectMapper mapper = new ObjectMapper(); In runtime want to serialize instance of class. What is the class the program doesn't known. It's object instance of parameterized type T.
How to ignore all properties (fields and getters) which marked specified annotation (javax.persistence.Id) ?
Example:
public static class PojoTest { @Id public String idTest; public String id; } public void serialize(Object object) { ObjectMapper objectMapper = new ObjectMapper(); // TODO ignore property mark @Id annotation Map<Object, Object> map = objectMapper.convertValue(object, Map.class); assertFalse(map.containsKey("idTest")); } public void test() { PojoTest pojoTest = new PojoTest(); pojoTest.id = "foo"; pojoTest.idTest = "bar"; serialize(pojoTest); }
@JsonIgnoreto those fields.