Add missing @JsonIdentityInfo handling for implicit Collections with DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY - #5537
Conversation
@JsonIdentityInfo handling for implicit collections with DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY
| ClassUtil.throwIfRTE(e); | ||
| } | ||
| // note: pass Object.class, not Object[].class, as we need element type for error info | ||
| throw JsonMappingException.wrapWithPath(e, Object.class, result.size()); |
There was a problem hiding this comment.
Or maybe _containerType.getContentType().getRawClass() instead of Object.class?
There was a problem hiding this comment.
That was copied from handleNonArray. I adjusted Object.class to _containerType.getContentType().getRawClass() in both places, because it seems more logical (and the tests still pass).
Good point -- docs are bit out of sync. The current branch for Jackson 2 would actually be But basically I can handle the details. |
|
@MoritzR200 Ok: first of all, thank you for contributing this! It seems like a good addition. And looks like you already sent CLA!!! Great. I'll try to get this reviewed soon (tomorrow if all goes well). |
…h DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY
@JsonIdentityInfo handling for implicit collections with DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY@JsonIdentityInfo handling for implicit collections with DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY
@JsonIdentityInfo handling for implicit collections with DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY@JsonIdentityInfo handling for implicit Collections with DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY
|
Merged into |
The issue fixed
The added unit test (see below) fails without my fix, because before in the
CollectionDeserializertheCollectionReferringAccumulator(that is to say proper reference handling) was only used in the case where the collection deserialized is represented by a proper JSON-array, which is however not the case for implicit single element collections, whenDeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAYis enabled.So (analogous to the previous handling for proper JSON-arrays) I added handling for implicit collections under the above circumstances, resolving the issue.
The added unit test for reference (MAPPER has
DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY):Related other issue
While fixing the above issue I also noticed that the
ObjectArrayDeserializerhas the same issue, because it has no handling of object references whatsoever. So the following test cases, fail both with and without theDeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY(though the first test should fail without that feature).I have created issue #5538 for that, because implementing that seams like something best left to the maintainers, since it (as far as I can tell) will not be trivial.
Potentially related issues
I am uncertain, whether #2780 might be related to this or not.
Other that that I found no related issues.
PS
Did I target the right branch? In jackson/CONTRIBUTING.md it says, that I should target the current stable branch (2.17??) which seems outdated. (It also mentions an nonexistent master branch.) So I changed to 2.20, but the other recent pull requests do target 3.x (even if they are small bug fixes), so you might want to consider updating your explanation.
Also It took me some time to figure out, that jackson-base (a required build-dependency) was contained in the jackson-bom project which is not listed as a dependency of this project, so you also might want to explain that somewhere to make creating pull requests a bit easier.