For simplicity here is a simple class:
class GetterMethodsObject {
int id = 10;
public int getId() {
return id;
}
// @JsonIgnore
public boolean isId() {
return true;
}
}
Serializing this object should give:
{"id":10}
as there is public getter method. Usage example:
mapper=new ObjectMapper();
mapper.writeValueAsString(object);
But I am getting exception:
com.fasterxml.jackson.databind.JsonMappingException:
Conflicting getter definitions for property "id": org.citi.facility.GetterMethodsObject#isId(0 params) vs org.citi.facility.GetterMethodsObject#getId(0 params)
As id
is Integer
so, I am expecting Jackson
to call getId()
method but not isId()
. isId()
method should be called only if id is boolean? Even I put @JsonIgnore
it is not helping. I can not change actual object. How to fix this issue?