diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 315ccfebb..2fc5a8a1b 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -4,6 +4,11 @@ Project: jackson-dataformat-xml === Releases === ------------------------------------------------------------------------ +2.12.4 (not yet released) + +#469: Empty tags cause incorrect deserialization of unwrapped lists + (reported by jackson-code1@github) + 2.12.3 (12-Apr-2021) #456: Fix JsonAlias with unwrapped lists diff --git a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/WrapperHandlingDeserializer.java b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/WrapperHandlingDeserializer.java index edfbdf2ec..ab8414dc5 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/WrapperHandlingDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/WrapperHandlingDeserializer.java @@ -4,6 +4,7 @@ import java.util.*; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.util.JsonParserDelegate; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.deser.*; @@ -154,7 +155,14 @@ protected final void _configureParser(JsonParser p) throws IOException p = ((JsonParserDelegate) p).delegate(); } if (p instanceof FromXmlParser) { - ((FromXmlParser) p).addVirtualWrapping(_namesToWrap, _caseInsensitive); + // 03-May-2021, tatu: as per [dataformat-xml#469] there are special + // cases where we get String token to represent XML empty element. + // If so, need to refrain from adding wrapping as that would + // override parent settings + JsonToken t = p.currentToken(); + if (t == JsonToken.START_OBJECT || t == JsonToken.START_ARRAY) { + ((FromXmlParser) p).addVirtualWrapping(_namesToWrap, _caseInsensitive); + } } } diff --git a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlReadContext.java b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlReadContext.java index 3bfe7ffea..c5d4ef8b8 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlReadContext.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlReadContext.java @@ -42,20 +42,19 @@ public final class XmlReadContext protected String _wrappedName; /* - /********************************************************** - /* Simple instance reuse slots; speeds up things - /* a bit (10-15%) for docs with lots of small - /* arrays/objects (for which allocation was + /********************************************************************** + /* Simple instance reuse slots; speeds up things a bit (10-15%) + /* for docs with lots of small arrays/objects (for which allocation was /* visible in profile stack frames) - /********************************************************** + /********************************************************************** */ protected XmlReadContext _child = null; /* - /********************************************************** + /********************************************************************** /* Instance construction, reuse - /********************************************************** + /********************************************************************** */ public XmlReadContext(XmlReadContext parent, int type, int lineNr, int colNr) @@ -90,9 +89,9 @@ public void setCurrentValue(Object v) { } /* - /********************************************************** + /********************************************************************** /* Factory methods - /********************************************************** + /********************************************************************** */ public static XmlReadContext createRootContext(int lineNr, int colNr) { @@ -128,9 +127,9 @@ public final XmlReadContext createChildObjectContext(int lineNr, int colNr) } /* - /********************************************************** + /********************************************************************** /* Abstract method implementation, overrides - /********************************************************** + /********************************************************************** */ @Override @@ -155,9 +154,9 @@ public final JsonLocation getStartLocation(Object srcRef) { } /* - /********************************************************** + /********************************************************************** /* Extended API - /********************************************************** + /********************************************************************** */ /** @@ -188,9 +187,9 @@ protected void convertToArray() { } /* - /********************************************************** + /********************************************************************** /* Overridden standard methods - /********************************************************** + /********************************************************************** */ /** diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser469FailingTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser469FailingTest.java index 71485fa5a..db7f0fb73 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser469FailingTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser469FailingTest.java @@ -83,6 +83,7 @@ public void testIssue469WithDefaults() throws Exception "\n" + " \n" + " \n" + +// " aaaa\n" + "\n"; Outer469 result = mapper.readValue(xmlInput, Outer469.class);