Skip to content

Commit

Permalink
Clean up merge of test #366
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 23, 2019
1 parent 1a9df80 commit cca0823
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
Expand Up @@ -12,7 +12,6 @@
import com.fasterxml.jackson.databind.jsontype.impl.ClassNameIdResolver;
import com.fasterxml.jackson.databind.jsontype.impl.MinimalClassNameIdResolver;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
import com.fasterxml.jackson.databind.type.TypeFactory;

import com.fasterxml.jackson.dataformat.xml.util.StaxUtil;

Expand Down
Expand Up @@ -14,26 +14,33 @@ public DoubleWrapper(Double value) {
}
}

protected static class Parent {
public Level1 level1;
}

protected static class Level1 {
public Level2 level2;
public String field; // this should not be needed, but an unknown element is thrown without it
}

protected static class Level2 {
public String ignored;
public String field;
}

private final XmlMapper MAPPER = newMapper();

public void testWithDoubleAsNull() throws Exception
{
DoubleWrapper bean = MAPPER.readValue(
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='true' /></DoubleWrapper>",
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><\n" +
" public void testDoesNotAffectHierarchy() throws Exception\n" +
" {\n" +
" String xml = \"<Parent xmlns:xsi=\\\"http://www.w3.org/2001/XMLSchema-instance\\\">\"\n" +
" + \"<level1>\"\n" +
" + \"<level2>\"\n" +
" + \"<ignored xsi:nil=\\\"true\\\"/>\"\n" +
" + \"<field>test-value</field>\"\n" +
" + \"</level2>\"\n" +
" + \"</level1>\"\n" +
" + \"</Parent>\";\n" +
" Parent bean = MAPPER.readValue(xml, Parent.class);\n" +
"\n" +
" assertNotNull(bean);\n" +
"\n" +
" // this should not be set, but having an xsi:nil field before it causes it to set the next field on the wrong class\n" +
" assertEquals(\"test-value\", bean.level1.field);\n" +
"\n" +
" // fails because field is set on level1 instead of on level2\n" +
" assertEquals(\"test-value\", bean.level1.level2.field);\n" +
" }\n" +
"d xsi:nil='true' /></DoubleWrapper>",
DoubleWrapper.class);
assertNotNull(bean);
assertNull(bean.d);
Expand Down Expand Up @@ -71,25 +78,4 @@ public void testRootPojoAsNonNull() throws Exception
Point.class);
assertNotNull(bean);
}

public void testDoesNotAffectHierarchy() throws Exception
{
String xml = "<Parent xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+ "<level1>"
+ "<level2>"
+ "<ignored xsi:nil=\"true\"/>"
+ "<field>test-value</field>"
+ "</level2>"
+ "</level1>"
+ "</Parent>";
Parent bean = MAPPER.readValue(xml, Parent.class);

assertNotNull(bean);

// this should not be set, but having an xsi:nil field before it causes it to set the next field on the wrong class
assertEquals("test-value", bean.level1.field);

// fails because field is set on level1 instead of on level2
assertEquals("test-value", bean.level1.level2.field);
}
}

0 comments on commit cca0823

Please sign in to comment.