-
-
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
Class name handling for Collections.unmodifiableList changed in 2.9.4-SNAPSHOT #1880
Comments
I am not sure I follow -- isn't this opposite of #1868? Where request specifically was not to change class name? |
Also: if I understand report correctly, I think I disagree here. Unmodifiable list and set should, I think, have identical behavior: either class name is changed to allow deserialization (but lose "unmodifiability"), or class name should remain exactly as is, but fail on deserialization unless custom deserializer is used. |
Thanks for the fast response. In both cases I'm asking that the behavior remain consistent through the patch releases (do not introduce breaking changes). For this specific issue, I think users are going to be caught off guard that the following test use to work, but no longer works: @Test
public void derializeUnmodifiableList() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
String actualJson = mapper.writeValueAsString(Collections.unmodifiableList(Collections.emptyList()));
// fails with exception
List<?> value = mapper.readValue(actualJson, List.class);
assertTrue(value instanceof List);
} |
@rwinch I still do not understand this. As far as I understand, code would have failed up until 2.9.2, but worked in 2.9.3 as a side-effect of #1823 which did not directly address it. It would have broken any custom deserializers similar to #1868, however. As such there is no way to make this work not change behavior of either 2.9.2 or 2.9.3. And if #1868 is to go through, I would think that behavior as it is now should stay: or, if not, then #1868 should also be rolled back. Benefit of going back to 2.9.2 way, with respect to unmodifiable types, is that user can at least register custom deserializer, or, if preferable, abstract type mapping. Or if nothing else helps, |
Thank you for your response.
My testing does not reflect this. From what I have experienced, the test does not break until 2.9.4-SNAPSHOT (it works in prior versions). NOTE: This test is for an unmodifiableList while #1868 is an unmodifiableSet
I can see this line of reasoning and is why I deliberated even reporting the issues so long. However, I think these changes would be better off outside of a patch release. In my opinion, telling users to create their own deserializer, mapping, or |
I should add that this is also happening in 2.8.11.1-SNAPSHOT |
Yes, behavior should be the same for both snapshots. Having thought about this bit more, I realized that maybe I should go for proper full solutions, which would:
For (2), I think we could:
This is quite a bit more work, but I think it really is the best way to go, now that some special handling is done. It will still allow custom deserializers (since class name is not modified) AND retain intended implementation type. This would also cover #1881. The only open thing would once again be 2.8.11: this change is still non-trivial wrt regression risk. So I will most likely do smallest change there (map name for "singleton", as per earlier fix). |
As to "making users use ClassNameIdResolver", yes; but you may be missing one aspect: up until 2.9.2 (and 2.8.10), deserialization was NOT working for these types. 2.9.3/2.8.11 did unintentionally allow this, but had problems for the other type. I do not believe users would be counting on this new behavior; and if they had work-arounds in place prior, would still have them. This is mostly wrt what 2.8.11.1 will have: I think |
Fixed (commit references #1880) so that:
This seems like a better fix to me, all around, although theoretically it is always possible someone somewhere might prefer conversion to standard types. Specifically, singleton/empty instances are implemented as read-only by JDK (I think), and if code expects these to be mutable this is not the case. Given bit bigger scope of the fix I will leave 2.8.11(.1) at something that approximates behavior of 2.8.10, and not merging this bundle of changes. Let me know what you think; I hope we can soon proceed with 2.9.4 at least regarding this class of issues. |
Hi, I'm looking into managing an upgrade from 2.8 to 2.10. I'm seeing some issues in backwards compatibility as a result of this issue (for example: 2.10 writes |
I have the same issue. We lost forward compatibility after jackson 2.8.8 -> >= 2.9.4 upgrade.
But we need change serialization of this private collection types and support deserialization possibility by previous service version. |
@antenko I don't know what is the situation here at this point. I'd suggest first trying the latest 2.9.x version, 2.9.10. It is quite possible that there is no way to support combination of class-based polymorphic type deserialization for specialized JDK collection types: and specifically there is not necessarily goal of trying to preserve exact handling of an old version like 2.8.8. |
Similar to #1868 the handling of
Collections.unmodifiableList
has changed in a non-passive manner. The following test passes prior to jackson-databind 2.9.4-SNAPSHOTHowever, it fails in jackson-databind 2.9.4-SNAPSHOT with the following error:
It could possibly be argued this is a bug that has been fixed. However, given the length of time this has been working this way I'd consider it a bug. This is compounded by the fact that in jackson-databind 2.9.4-SNAPSHOT the following fails:
with the following exception:
I think it would be ideal to revert jackson-databind 2.9.4-SNAPSHOT to serializing
Collections.unmodifiableList
in the same way it was prior to 2.9.4-SNAPSHOTThe text was updated successfully, but these errors were encountered: