Skip to content

Commit

Permalink
Fixed #314 and #390 (same root cause)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 6, 2020
1 parent 38ffd8a commit fcdc96d
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 141 deletions.
15 changes: 13 additions & 2 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,23 @@ Joseph Petersen (jetersen@github)
* Reported #273: Input mismatch with case-insensitive properties
(2.12.0)

Ghenadii Batalski (ghenadiibatalski@github)
Eduard Wirch (ewirch@github)

* Reported #377: `ToXmlGenerator` ignores `Base64Variant` while serializing `byte[]`
* Reported #314: Jackson gets confused by parent list element
(2.12.0)

Jochen Schalanda (joschi@github)

* Reported #318: XMLMapper fails to deserialize null (POJO reference) from blank tag
(2.12.0)

Ghenadii Batalski (ghenadiibatalski@github)

* Reported #377: `ToXmlGenerator` ignores `Base64Variant` while serializing `byte[]`
(2.12.0)

David Schmidt (d-schmidt@github)

* Reported #390: Unexpected attribute at string fields causes extra objects to be
created in parent list
(2.12.0)
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ Project: jackson-dataformat-xml
(requested by Dave J)
#273: Input mismatch with case-insensitive properties
(reported by Joseph P)
#314: Jackson gets confused by parent list element
(reported by Eduard W)
#318: XMLMapper fails to deserialize null (POJO reference) from blank tag
(reported by Jochen S)
#319: Empty root tag into `List` deserialization bug
(reported by Seatec13@github)
#377: `ToXmlGenerator` ignores `Base64Variant` while serializing `byte[]`
(reported by Ghenadii B)
#390: Unexpected attribute at string fields causes extra objects to be
created in parent list
(reported by David S
#397: `XmlReadContext` does not keep track of array index
#403: Make `JsonNode` implicitly create `ArrayNode`s for repeated XML Elements
#405: Mixed content not exposed through `FromXmlParser`, lost by `JsonNode`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public boolean isExpectedStartArrayToken()
_xmlTokens.skipAttributes();
return true;
}
//System.out.println(" isExpectedArrayStart?: t="+t);
//System.out.println(" FromXmlParser.isExpectedArrayStart?: t="+t);
return (t == JsonToken.START_ARRAY);
}

Expand Down Expand Up @@ -887,6 +887,7 @@ public String getValueAsString(String defValue) throws IOException
_nextToken = null;
// One more thing: must explicitly skip the END_OBJECT that would follow
_skipEndElement();
//System.out.println(" FromXmlParser.getValueAsString() on START_OBJECT, str == '"+str+"'");
return (_currText = str);
}
} catch (XMLStreamException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,11 @@ protected String convertToString() throws XMLStreamException
if (text == null) {
text = "";
}
if (_currentWrapper != null) {
_currentWrapper = _currentWrapper.getParent();
}
// 06-Jun-2020, tatu: As per [dataformat-xml#390], doing this is wrong,
// should not (at least always?) assume we need it
// if (_currentWrapper != null) {
// _currentWrapper = _currentWrapper.getParent();
// }
// just for diagnostics, reset to element name (from first attribute name)
_localName = _xmlReader.getLocalName();
_namespaceURI = _xmlReader.getNamespaceURI();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.databind.*;

import com.fasterxml.jackson.dataformat.xml.*;
import com.fasterxml.jackson.dataformat.xml.annotation.*;

public class ListWithAttributes extends XmlTestBase
public class ListWithAttributesDeserTest extends XmlTestBase
{
// [dataformat-xml#43]
static class Name {
Expand Down Expand Up @@ -79,6 +81,43 @@ static class ChildB301 {
public Double value;
}

// [dataformat-xml#314]
static class Customer314 {
@JacksonXmlElementWrapper(localName = "Customer", useWrapping = false)
@JacksonXmlProperty(localName = "Address")
public List<Address314> address;
}

static class Address314 {
public String stateProv;
public CountryName314 countryName;
}

static class CountryName314 {
public String code;
@JacksonXmlText
public String name;
}

// [dataformat-xml#390]
@JacksonXmlRootElement(localName = "many")
static class Many390 {
@JacksonXmlProperty(localName = "one")
@JacksonXmlElementWrapper(useWrapping = false)
List<One390> ones;
}

static class One390 {
@JacksonXmlProperty
String value;
@JacksonXmlProperty
String another;

public void setAnother(String s) {
another = s;
}
}

/*
/**********************************************************
/* Test methods
Expand All @@ -87,6 +126,10 @@ static class ChildB301 {

private final ObjectMapper MAPPER = newMapper();

private final ObjectMapper UPPER_CASE_MAPPER = mapperBuilder()
.propertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE)
.build();

// [dataformat-xml#43]
public void testIssue43() throws Exception
{
Expand Down Expand Up @@ -142,5 +185,63 @@ public void testIssue301WithAttr() throws Exception {
assertEquals(1, result.childrenB.size());
assertEquals(Double.valueOf(12.25), result.childrenB.get(0).value);
}

// [dataformat-xml#314]
public void testDeser314Order1() throws Exception
{
String content = ""
+ "<Customer>\n"
+ " <Address>\n"
+ " <StateProv StateCode='DE-NI'>Niedersachsen</StateProv>\n"
+ " <CountryName Code='DE'>Deutschland</CountryName>\n"
+ " </Address>\n"
+ "</Customer>"
;
Customer314 result = UPPER_CASE_MAPPER.readValue(content, Customer314.class);
assertNotNull(result);
}

public void testDeser314Order2() throws Exception
{
String content = ""
+ "<Customer>\n"
+ " <Address>\n"
+ " <CountryName Code='DE'>Deutschland</CountryName>\n"
+ " <StateProv StateCode='DE-NI'>Niedersachsen</StateProv>\n"
+ " </Address>\n"
+ "</Customer>"
;
Customer314 result = UPPER_CASE_MAPPER.readValue(content, Customer314.class);
assertNotNull(result);
}

public void testDeser314Address() throws Exception
{
String content = ""
+ " <Address>\n"
+ " <CountryName Code=\"DE\">Deutschland</CountryName>\n"
+ " <StateProv StateCode=\"DE-NI\">Niedersachsen</StateProv>\n"
+ " </Address>\n"
;
Address314 result = UPPER_CASE_MAPPER.readValue(content, Address314.class);
assertNotNull(result);
}

// [dataformat-xml#390]
public void testDeser390() throws Exception
{
String XML = "<many>\n"
+ " <one>\n"
+ " <value bar=\"baz\">foo</value>\n"
+ " <another>stuff</another>\n"
+ " </one>\n"
+ "</many>";
Many390 many = MAPPER.readValue(XML, Many390.class);
assertNotNull(many.ones);
//System.err.println("XML:\n"+MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(many));
assertEquals(1, many.ones.size());
assertEquals("foo", many.ones.get(0).value);
assertEquals("stuff", many.ones.get(0).another);
}
}

0 comments on commit fcdc96d

Please sign in to comment.