Skip to content

Commit

Permalink
Fix #469 (yet another issue with unwrapped lists)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 3, 2021
1 parent 64532a1 commit d9738d9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -90,9 +89,9 @@ public void setCurrentValue(Object v) {
}

/*
/**********************************************************
/**********************************************************************
/* Factory methods
/**********************************************************
/**********************************************************************
*/

public static XmlReadContext createRootContext(int lineNr, int colNr) {
Expand Down Expand Up @@ -128,9 +127,9 @@ public final XmlReadContext createChildObjectContext(int lineNr, int colNr)
}

/*
/**********************************************************
/**********************************************************************
/* Abstract method implementation, overrides
/**********************************************************
/**********************************************************************
*/

@Override
Expand All @@ -155,9 +154,9 @@ public final JsonLocation getStartLocation(Object srcRef) {
}

/*
/**********************************************************
/**********************************************************************
/* Extended API
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -188,9 +187,9 @@ protected void convertToArray() {
}

/*
/**********************************************************
/**********************************************************************
/* Overridden standard methods
/**********************************************************
/**********************************************************************
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void testIssue469WithDefaults() throws Exception
"<outer>\n" +
" <inner1/>\n" +
" <inner2 str2='aaaa'/>\n" +
// " <inner2><str2>aaaa</str2></inner2>\n" +
"</outer>\n";

Outer469 result = mapper.readValue(xmlInput, Outer469.class);
Expand Down

0 comments on commit d9738d9

Please sign in to comment.