Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a test that demonstrates issue 86 #87

Merged
merged 1 commit into from
Dec 26, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.fasterxml.jackson.dataformat.xml.unwrapped;

import java.util.Arrays;
import java.util.List;

import junit.framework.Assert;

import org.junit.Test;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

public class TestIssue86 {

@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);
Assert.assertEquals(source, xml);

final Issue86 after = mapper.readValue(xml, Issue86.class);
Assert.assertEquals(before, after);
}

@JacksonXmlRootElement(localName = "test")
public static class Issue86 {

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

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

public Issue86() {}

public Issue86(final String id, final List<Issue86> children) {
this.id = id;
this.children = children;
}

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

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

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

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

}