Skip to content

Commit

Permalink
Minor fix to keep #86 test case working properly (failing for real re…
Browse files Browse the repository at this point in the history
…ason, as opposed to failing due to missing test method)
  • Loading branch information
cowtowncoder committed Dec 26, 2015
1 parent d728897 commit 764c97a
Showing 1 changed file with 39 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
Expand All @@ -18,11 +16,11 @@ public class TestUnwrappedDeserIssue86 extends XmlTestBase
public static class Issue86 {

@JacksonXmlProperty(localName = "id", isAttribute = true)
private String id;
public String id;

@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "test")
private List<Issue86> children;
public List<Issue86> children;

public Issue86() {}

Expand All @@ -33,20 +31,15 @@ public Issue86(final String id, final List<Issue86> children) {

@Override
public boolean equals(final Object other) {
if (other == null) {
return false;
}

if (other == this) {
return true;
}
if (other == this) return true;
if (other == null) return false;

if (!(other instanceof Issue86)) {
return false;
}
if (!(other instanceof Issue86)) {
return false;
}

final Issue86 otherIssue86 = (Issue86) other;
return otherIssue86.id.equals(id) && otherIssue86.children.equals(children);
final Issue86 otherIssue86 = (Issue86) other;
return otherIssue86.id.equals(id) && otherIssue86.children.equals(children);
}
}

Expand All @@ -56,34 +49,34 @@ public boolean equals(final Object other) {
/***********************************************************************
*/

@Test
public void deserializeUnwrappedListWhenLocalNameForRootElementAndXmlPropertyMatch() throws Exception {
final String source =
"<test id=\"0\">" +
"<test id=\"0.1\">" +
"<test id=\"0.1.1\"/>" +
"</test>" +
"<test id=\"0.2\"/>" +
"<test id=\"0.3\">" +
"<test id=\"0.3.1\"/>" +
"</test>" +
"</test>";

final Issue86 before = new Issue86("0",
Arrays.asList(new Issue86("0.1",
Arrays.asList(new Issue86("0.1.1", null))),
new Issue86("0.2", null),
new Issue86("0.3",
Arrays.asList(
new Issue86("0.3.1", null)))));

final XmlMapper mapper = new XmlMapper();
mapper.setSerializationInclusion(Include.NON_NULL);

final String xml = mapper.writeValueAsString(before);
assertEquals(source, xml);

final Issue86 after = mapper.readValue(xml, Issue86.class);
assertEquals(before, after);
}
public void testDeserializeUnwrappedListWhenLocalNameForRootElementAndXmlPropertyMatch() throws Exception
{
final String source =
"<test id=\"0\">" +
"<test id=\"0.1\">" +
"<test id=\"0.1.1\"/>" +
"</test>" +
"<test id=\"0.2\"/>" +
"<test id=\"0.3\">" +
"<test id=\"0.3.1\"/>" +
"</test>" +
"</test>";
final Issue86 before = new Issue86("0",
Arrays.asList(new Issue86("0.1",
Arrays.asList(new Issue86("0.1.1", null))),
new Issue86("0.2", null),
new Issue86("0.3",
Arrays.asList(
new Issue86("0.3.1", null)))));
final XmlMapper mapper = new XmlMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
final String xml = mapper.writeValueAsString(before);
assertEquals(source, xml);
final Issue86 after = mapper.readValue(xml, Issue86.class);
assertEquals(before, after);
}
}

0 comments on commit 764c97a

Please sign in to comment.