Skip to content

Commit

Permalink
Add a unit test for #101
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 14, 2014
1 parent 5fc1112 commit 3069602
Showing 1 changed file with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.*;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
import com.fasterxml.jackson.dataformat.xml.annotation.*;
Expand All @@ -27,6 +28,32 @@ static class Optionals {
public List<Optional> optional;
}

// For [Issue#101]
@JacksonXmlRootElement(localName = "root")
@JsonPropertyOrder({ "unwrapped", "name" })
static class Root {
@JacksonXmlProperty(localName = "unwrapped")
@JacksonXmlElementWrapper(useWrapping = false)
public List<UnwrappedElement> unwrapped;

public String name;
}

static class UnwrappedElement {
public UnwrappedElement () {}

public UnwrappedElement (String id, String type) {
this.id = id;
this.type = type;
}

@JacksonXmlProperty(isAttribute = true)
public String id;

@JacksonXmlProperty(isAttribute = true)
public String type;
}

/*
/**********************************************************
/* Unit tests
Expand All @@ -51,4 +78,29 @@ public void testOptionalsWithMissingType() throws Exception
assertEquals("123-456-7890", opt.number);
assertEquals("NOT SET", opt.type);
}
}

// [Issue#101]
public void testWithTwoAttributes() throws Exception
{
final String EXP = "<root>"
+"<unwrapped id=\"1\" type=\"string\"/>"
+"<unwrapped id=\"2\" type=\"string\"/>"
+"<name>test</name>"
+"</root>";
Root rootOb = new Root();
rootOb.unwrapped = Arrays.asList(
new UnwrappedElement("1", "string"),
new UnwrappedElement("2", "string")
);
rootOb.name = "test";

// First, serialize, which works
String xml = MAPPER.writeValueAsString(rootOb);
assertEquals(EXP, xml);

// then try deserialize
Root result = MAPPER.readValue(xml, Root.class);
assertNotNull(result);
assertEquals(rootOb.name, result.name);
}
}

0 comments on commit 3069602

Please sign in to comment.