Reputation: 602
This is my class
public class HouseJPAImpl implements House {
public RoomJPAImpl room;
public RoomJPAImpl getRoom(){
return this.room;
}
public void setRoom(RoomJPAImpl room){
this.room = room;
}
@Override
public boolean isRoom(){
return false;
}
}
My code gets confused with getRoom and isRoom.
Caused by: java.lang.IllegalArgumentException: Conflicting getter definitions for property "room": com.shared.model.restimpl.jpa.HouseJPAImpl#getRoom(0 params) vs com.shared.model.restimpl.jpa.HouseJPAImpl#isRoom(0 params)
I tried putting the @jsonignore on the isRoom method but then i dont get the room property in JSON.
Is there a way to use the getRoom over isRoom?
Upvotes: 0
Views: 661
Reputation: 116522
First of all, this is something that Jackson 2.3 will handle gracefully (see https://github.com/FasterXML/jackson-databind/issues/238).
But until it gets released, there are 2 main ways to handle this:
@JsonIgnore
on isRoom()
, but keep @JsonProperty
on getRoom()
isXxx()
methods: can either set global settings (ObjectMapper
has something like setVisibility
), or use annotation @JsonAutoDetect
on classesIf this is an isolated case, you are probably better off by just using first one.
Upvotes: 2