Jackson Serialization - @JsonProperty conflicts with another getter

13 views
Skip to first unread message

DGV

unread,
Jan 6, 2020, 12:44:10 PM1/6/20
to jackson-user
Here is my SO post describing the problem i am facing.
https://stackoverflow.com/questions/59602625/jackson-serialization-jsonproperty-conflicts-with-another-getter

Details. 

I upgraded Spring 4.3 to Spring 5.2. The Jackson library also got upgraded from 2.8.3 to 2.10.

I am experiencing the following problem with Serialization

Currently (in 2.8.3) when i apply the JsonView "D.class" and serialize SubClass.java, i see "title" as a json property in the response. After upgrading to 2.10, I do not see "title" in the reponse. It seems like it does not like the fact that there is a getter method in the SuperClass as getTitle. If i change the JsonProperty from "title" to "title1", it works. I am now wondering how it worked fine in Jackson 2.8.3. Could it be possible that the JsonView (D. class) is not getting applied properly in 2.10 causing Jackson to see both the getter Methods as a conflict?



public class SuperClass {

     @JsonView({A.class, B.class})
     public String getTitle(){}

}


public class SubClass extends SuperClass {

     @JsonView({A.class, B.class, C.class, D.class})
     @JsonProperty("title")
     public String getArticleTitle(){}

}

Tatu Saloranta

unread,
Jan 6, 2020, 12:49:20 PM1/6/20
to jackson-user
This could be a bug, since resolving the case is bit complicated from Jackson perspective -- after all, not only does it need to resolve all annotations throughout inheritance hierarchy (which JDK itself won't do), merge them from different accessors (getter/setter/field), but also handle case of renaming as done here to associate accessors in 2 dimensions.
Changes to logic handling this processing are made to fix other found issues but occasionally there can be regressions for cases that are not tested, such as this one.

But one more thing that is needed would be actual code used for serialization, to know for sure how ObjectWriter (or, if possible, ObjectMapper directly?) is used for writing.

-+ Tatu +-



 
Reply all
Reply to author
Forward
0 new messages