vendredi 8 mai 2015

Jackson conflicting property and getter definitions

I'm extending following third-party class which I can't change:

public class Page {
    @JsonProperty("content")
    private String content;

    public String getContent() {};
}

My implementation of Page looks like this:

public class MyPage extends Page {
    @JsonProperty("my-content")
    public String getContent() {return super.getContent()};
}

When I'm trying to serialize instance of MyPage class I get the following exception:

java.lang.IllegalStateException: Conflicting property name definitions:  
'content' (for [field com.test.Page#content]) 
vs
'my-content' (for [method com.test.MyPage#getContent(0 params)])

Is there an easy way to force serializer to produce 'my-content' property?

Aucun commentaire:

Enregistrer un commentaire