Re: [jackson-user] Jackson Serialization - @JsonProperty conflicts with another getter

2020-01-06 Thread Tatu Saloranta
On Mon, Jan 6, 2020 at 9:44 AM DGV  wrote:

> 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(){}
> }
>
>
>
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 +-

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAGrxA27aAN75OniP9NQFqFrL06rrTnRZ6mDEJY9UAvcshAqFRw%40mail.gmail.com.


Re: [jackson-user] Jackson serialization

2017-08-11 Thread Tatu Saloranta
Since you are using default typing, this is how things work -- why would
you not expect type information?

Perhaps you could share your object model and explain why you think typing
should not affect contents the way it does.

-+ Tatu +-

ps. In future when asking questions about "why does X happen" it is useful
to include information about your settings -- at least non-default ones.
  Default typing is not one of default settings and while commonly used it
is probably not enabled by majority of users.


On Fri, Aug 11, 2017 at 5:51 AM, Grigoriy Marakov  wrote:

> Hello everyone! I have a problem with serialization via Jackson.
> When i do JsonNode smth = readValueToTree(obj) I get information about
> class type (e.g. java.Math.BigInteger, java.lang.ArrayList). This problem
> pop up for entities contains Map without any serializer.
> Also in entity which is not full filled. E.g. I have class ContactMethod
> which contains several fields. If all information is present then problem
> goes away. But if filled only one field with id (type bigInteger) then i
> catch class type info:
> Expected:
>
> "contactMethods": [
> "@type": "PhoneNumber",
> "id": "9148293419813662646",
>
> Actual:
>
> "contactMethods": ["java.util.ArrayList",
> "@type": "PhoneNumber",
> "id": "9148293419813662646"
>
> Another example (with map serialization):
> My class have chars (Map). Expected, that when I'll
> serialize it I'll get:
>
> "chars": { "char": [ 1 ] },
>
> but actual I get:
>
> "chars": {"char": ["java.math.BigInteger", 1]}
>
> Anyone knows why it happens? Thanks
>
>
> I got the answer like:
>
> From symptoms it looks like you have enabled "default typing" (there are
> multiple methods in ObjectMapper to do that), which forces inclusion of
> type information similar to what happens when you use @JsonTypeInfo
>  annotation.
> You will want to disable this setting, or use explicit @JsonTypeInfo(use
> = Id.NONE) to disable polymorphic handling for specific field(s).
>
>
> But,  I have enabled "default typing" and @jsontypeinfo(use = Id.CLASS), I
> need it in the other reasons.
>
> This problem appears strangely:
>
> [image: problem]
>
> Birthday and contactMethods are located under contacts.
> But if contactMethods is located in the first level like contacts - all is
> ok
>
> [image: problem2]
>
> --
> You received this message because you are subscribed to the Google Groups
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.