From c3b48f3977ef5343ba32d9fe9d566e11d0c88ca5 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 10 May 2024 12:46:15 -0700 Subject: [PATCH] Fix #509 (re-created #651 with changes) (#652) --- release-notes/CREDITS-2.x | 8 ++++++++ release-notes/VERSION-2.x | 6 ++++++ .../jackson/dataformat/xml/deser/FromXmlParser.java | 10 +++++++++- .../UnexpectedNonWhitespaceText509Test.java | 6 ++++-- 4 files changed, 27 insertions(+), 3 deletions(-) rename src/test/java/com/fasterxml/jackson/dataformat/xml/{failing => deser}/UnexpectedNonWhitespaceText509Test.java (90%) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 67cc18d06..9927dce7d 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -243,3 +243,11 @@ Motonori IWAMURO (vmi@github) * Contributed fix for #616: Fix mismatch in `setNextIsUnwrapped(boolean)` in `XmlBeanSerializerBase#serializeFieldsFiltered()` (2.16.1) + + Dennis Cornwell (@cornwe19) + +* Reported #509: Exception when parsing `List`s of mixed content (since 2.13.0) + +Christopher R. Wicks (@wickstopher) + +* Contributed fix for #509: Exception when parsing `List`s of mixed content (since 2.13.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 09dfa66ba..83107a9b5 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -4,6 +4,12 @@ Project: jackson-dataformat-xml === Releases === ------------------------------------------------------------------------ +2.16.3 (not yet released) + +#509: Exception when parsing `List`s of mixed content (since 2.13.0) + (reported by Dennis C) + (fix contributed by Christopher R. W) + 2.16.2 (09-Mar-2024) No changes since 2.16.1 diff --git a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java index 12a716ed8..269f7d8b9 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java @@ -847,9 +847,17 @@ public JsonToken nextToken() throws IOException } // 29-Mar-2021, tatu: This seems like an error condition... // How should we indicate it? As of 2.13, report as unexpected state + /* throw _constructError( -"Unexpected non-whitespace text ('"+_currText+"' in Array context: should not occur (or should be handled)" +"Unexpected non-whitespace text ('"+_currText+"') in Array context: should not occur (or should be handled)" ); + */ + + // [dataformat-xml#509] 2.13 introduced a defect in which an Exception was thrown above, breaking + // parsing of mixed content arrays (https://github.com/FasterXML/jackson-dataformat-xml/issues/509). + // This exception case was removed to enable continued support of that functionality, but more + // robust state handling may be in order. + // See comment https://github.com/FasterXML/jackson-dataformat-xml/pull/604 } // If not a leaf (or otherwise ignorable), need to transform into property... diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnexpectedNonWhitespaceText509Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UnexpectedNonWhitespaceText509Test.java similarity index 90% rename from src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnexpectedNonWhitespaceText509Test.java rename to src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UnexpectedNonWhitespaceText509Test.java index 0059dbc4c..1d7f2c037 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnexpectedNonWhitespaceText509Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UnexpectedNonWhitespaceText509Test.java @@ -1,12 +1,12 @@ -package com.fasterxml.jackson.dataformat.xml.failing; +package com.fasterxml.jackson.dataformat.xml.deser; import java.util.*; import org.junit.Test; import com.fasterxml.jackson.annotation.JsonPropertyOrder; - import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; @@ -31,6 +31,8 @@ public void setKey(java.lang.String value) { } static class MetaData { + @JacksonXmlElementWrapper(useWrapping = false) + @JacksonXmlProperty(localName = "data") protected List data; public List getData() {