Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	release-notes/VERSION-2.x
#	src/test/java/com/fasterxml/jackson/dataformat/xml/deser/JsonNodeBasicDeserTest.java
#	src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UntypedObjectDeserTest.java
  • Loading branch information
cowtowncoder authored and alex-bel-apica committed Sep 4, 2020
1 parent b31bad6 commit c1f159e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.JsonNodeType;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
import org.junit.Ignore;

public class JsonNodeBasicDeserTest extends XmlTestBase
{
Expand All @@ -19,8 +20,8 @@ public void testSimpleNode() throws Exception
assertEquals("123", root.get("attr").textValue());
}

// [dataformat-xml#403]: Allow sequences
/* //dups handling from databind 2.12 is required
// [dataformat-xml#403]: Allow sequences
public void testRepeated() throws Exception
{
JsonNode root = XML_MAPPER.readTree("<root><value>a</value><value>b</value></root>");
Expand All @@ -32,5 +33,23 @@ public void testRepeated() throws Exception
assertEquals("a", root.at("/value/0").asText());
assertEquals("b", root.at("/value/1").asText());
}
// [dataformat-xml#405]: support mixed content
public void testMixedContent() throws Exception
{
JsonNode fromXml = XML_MAPPER.readTree("<root>first<a>123</a>second<b>abc</b>last</root>");
final ObjectNode exp = XML_MAPPER.createObjectNode();
exp.putArray("")
.add("first")
.add("second")
.add("last");
exp.put("a", "123");
exp.put("b", "abc");
if (!fromXml.equals(exp)) {
ObjectWriter w = new JsonMapper().writerWithDefaultPrettyPrinter();
fail("Expected:\n"+w.writeValueAsString(exp)+"\ngot:\n"+w.writeValueAsString(fromXml));
}
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
import org.junit.Ignore;

// for [dataformat-xml#205], handling "untyped" ({@code java.lang.Object}-targeted)
// deserialization, including handling of element sequences
@Ignore //dups handling from databind 2.12 is required
public class UntypedObjectDeser205Test extends XmlTestBase
public class UntypedObjectDeserTest extends XmlTestBase
{
private static final String EOL = System.lineSeparator();

private final ObjectMapper XML_MAPPER = newMapper();

private final ObjectMapper JSON_MAPPER = new JsonMapper();

// for [dataformat-xml#205], handling "untyped" ({@code java.lang.Object}-targeted)
// deserialization, including handling of element sequences
public void testRepeatingElements() throws Exception
{
final String XML =
"<person>" +
"<person>\n" +
" <name>John</name>\n" +
" <parent>Jose</parent>\n" +
" <parent>Maria</parent>\n" +
Expand All @@ -43,8 +39,8 @@ public void testRepeatingElements() throws Exception
" </dog>\n" +
" </dogs>\n" +
"</person>";
final JsonNode fromXml = JSON_MAPPER.valueToTree(XML_MAPPER.readValue(XML, Object.class));
final ObjectNode exp = JSON_MAPPER.createObjectNode();
final JsonNode fromXml = XML_MAPPER.valueToTree(XML_MAPPER.readValue(XML, Object.class));
final ObjectNode exp = XML_MAPPER.createObjectNode();
exp.put("name", "John");
{
exp.putArray("parent")
Expand All @@ -64,7 +60,26 @@ public void testRepeatingElements() throws Exception
.put("age", "14");
}
if (!fromXml.equals(exp)) {
ObjectWriter w = JSON_MAPPER.writerWithDefaultPrettyPrinter();
ObjectWriter w = new JsonMapper().writerWithDefaultPrettyPrinter();
fail("Expected:\n"+w.writeValueAsString(exp)+"\ngot:\n"+w.writeValueAsString(fromXml));
}
}

// [dataformat-xml#405]: support mixed content
public void testMixedContent() throws Exception
{
final String XML = "<root>first<a>123</a>second<b>abc</b>last</root>";
final JsonNode fromXml = XML_MAPPER.valueToTree(XML_MAPPER.readValue(XML, Object.class));
final ObjectNode exp = XML_MAPPER.createObjectNode();
exp.putArray("")
.add("first")
.add("second")
.add("last");
exp.put("a", "123");
exp.put("b", "abc");

if (!fromXml.equals(exp)) {
ObjectWriter w = new JsonMapper().writerWithDefaultPrettyPrinter();
fail("Expected:\n"+w.writeValueAsString(exp)+"\ngot:\n"+w.writeValueAsString(fromXml));
}
}
Expand Down

0 comments on commit c1f159e

Please sign in to comment.