-
-
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
StringCollectionSerializer
calls JsonGenerator.setCurrentValue(value)
, which messes up current value for sibling properties
#2475
Comments
StringCollectionSerializer
calls JsonGenerator.setCurrentValue(value)
, which messes up current value for sibling properties
Thank you for reporting the issue. Sounds like a bug. Since |
Ok. I must admit I am not sure I fully follow what would be the expected behavior here, at every given point. I can see there is a discrepancy, but I am not sure which serializers are doing the right thing. Perhaps |
Yes, I think call needs to be right after |
@cowtowncoder Can the call to setCurrentValue be moved to serializeContents? This is what IndexedStringListSerializer and CollectionSerializer do. I agree that it needs to be after writeStartArray because that call creates a new context just for the array and doesn't overwrite the current context for the array's "parent", which in my example is Item |
I think I'll just start using new (in 2.10) My main concern is adding unit tests to try to sort of define expected behavior: the whole "current value" concept is (alas) quite undefined; so while fix itself looks easy enough, it'd be good to both find other cases (I'm sure they exist) and to guard against otherwise possible regressions from refactoring. |
Versions: 2.9.9 and 2.10.0.pr3
Given the following class definition:
You'll notice that when the serializer writes out the set and id properties, the current value on jgen is HashSet not the Item. I write a Jackson filtering library and I count on the current value being correct.
Doing some digging, I noticed that the StringCollectionSerializer sets the currentValue in the serialize method like so:
However, the current value is not explicity set in IndexedStringListSerializer nor CollectionSerializer, and consequently they both don't exhibit this problem
I have attached a java class that exhibits this behavior as long as you're using Jackson version 2.9.9 or later
Test.java.zip
The text was updated successfully, but these errors were encountered: