- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 228
XmlMapper
fails to parse XML array when the array only has one level
#498
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
Comments
Experiencing a similar issue with XML lists: <?xml version="1.0" encoding="utf-8"?>
<ContentMeta>
<Type>Application</Type>
<Id>0x01006fe013472000</Id>
<Version>0</Version>
<Content>
<Type>Program</Type>
<Id>2b0153c1bb7ceb9cd84e7eb9e0e2288d</Id>
</Content>
<Content>
<Type>Control</Type>
<Id>32ec02fa4709c28a099d6670590e025b</Id>
</Content>
</ContentMeta> data class ContentMeta(
val type: String,
val id: String,
val version: Int,
val content: Content // not a list -> gets last
)
mapper.readValue<ContentMeta>(xml)
// => ContentMeta(type="Application", id="0x01006fe013472000", version=0, content=Content(type="Control")) data class ContentMeta(
val type: String,
val id: String,
val version: Int,
val content: List<Content> // list -> fails
)
mapper.readValue<ContentMeta>(xml)
// => Exception in thread "Indexing thread" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `Content` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('Program')
|
@ericcwlaw Looks like a bug, yes. @Martmists-GH Not same issue just because there's |
@Martmists-GH quick note: not sure why, but use of nominal target of I will add a failing test first, see if I can figure out what might be causing the problem. I'll also try to see if this might be different with root values (where generic types are a constant source of issues) vs. "Map as a property" (wrapper POJO with single |
Ok another little note: use of Wrapper POJO like:
also changes things so that binding works as expected. So the problem affects only the specific case of Root value being bound as |
Note to self: use of "untyped" target ( |
Fixed via |
XmlMapper
fails to parse XML array when the array only has one level
Version used
Java versions tested
OpenJDK 1.8, 11 and 16
Test data
Incorrect result
by XmlMapper readValue(string, Map.class) method
The array (as "lists" in the test data) contains 6 elements but XmlMapper returns only the last element.
The text was updated successfully, but these errors were encountered: