Pregunta

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?

¿Fue útil?

Solución

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:

  • Add @JsonIgnore on isRoom(), but keep @JsonProperty on getRoom()
  • Change visibility settings to filter out all isXxx() methods: can either set global settings (ObjectMapper has something like setVisibility), or use annotation @JsonAutoDetect on classes

If this is an isolated case, you are probably better off by just using first one.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top