-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonFormat.Shape.OBJECT ignored when class implements Map.Entry #865
Comments
This is the problem with various add-on interfaces, including In this case serializer does not look at There are other possible approaches to take, to try to figure out whether what we have is "pure" I am open to suggestions for handling this, but unfortunately I am not sure use of |
Basically in 2.4 I had the @JsonProperty tags on the actual getValue(), getKey() and setKey(String) methods. This was to fix the deserialization problem found #565. I was building the Map.Entry objects from a BUS data packet, and serializing them out for later use in a List. It was convenient when I reloaded them and into a custom map. But looking at the code, I really do not need to implement Map.Entry to do that. I can workaround this problem. I think I can workaround, but because Map.Entry is an interface, it can be used to designate only one aspect of a multifaceted object. You need to choose whether to simply announce that use of Map.Entry as an API on a custom Serialized POJO is not supported. Alternatively, you may need to have the system do some annotation checking. There may be people who want the new behavior for their custom Map.Entry. Perhaps they could directly specify that with JSONFormat.shape.MAP_ENTRY. This would have to be the assumed default for any Map.Entry object that is not annotated with a JSONFormat. Just some thoughts. |
@DaveGrahamCA Yes. Apologies for this breakage, I did not quite realize that As to solutions, |
Thinking about this a bit more, I think that use of I may also file an issue for annotations to indicate a new choice (maybe |
I just got burned by this change too. My class that Implements Map.Entry is now (as of 2.5.0) serialized without the attribute names, BUT the Jackson deserializer still wants the names. Are there any workarounds (the work with the 2.5.0 version, not a later one) that will allow:
Any help would be appreciated. |
Unfortunately there is no functionality to change the behavior at this point, except by using custom serializer/deserializer for Further, for 2.5 only bug fixes are allowed, no functional changes, so adding new features (or enum values, like Features) is unfortunately not an option. |
Okay. For the sake of others, here is a workaround I used to force deserialization to use the OLD format (for my class named MapEntry):
|
And this an alternate workaround that forces deserialization to use the NEW format (and NOT the OLD) for my class named MapEntry:
|
Support for class annotation has been added for 2.9, as requested. One thing that does not work yet, however, is use on property. I hope to get that working, although that is much more difficult to support since it would require somehow constructing |
The change #565 has overridden the default behavior that is defined by annotations when using JsonFormat.Shape.OBJECT. This is problematic if the Map.Entry is only one aspect of the object. Below is example code that exposes this defect. It represents an attempt to implement the pre Jackson-2.5 behavior for a Map.Entry by forcing the jackson to deal with object as a POJO. But instead of reading the annotations as if it were a POJO it appears to serialize as by using some default Map.Entry algorithm. The behavior is not as expected after annotating the class. This code use to work with Jackson 2.4.
Example files
...
package example;
...
The text was updated successfully, but these errors were encountered: