Skip to content

Commit

Permalink
backport #148 test
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 7, 2020
1 parent 04014bf commit 6c46d9b
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
Expand Down Expand Up @@ -44,13 +46,35 @@ public StringListBean(String... texts)
}
}

// [dataformat-xml#148]
static class Bean148 {
@JsonProperty("item")
@JacksonXmlElementWrapper(localName = "list")
public Iterator<String> items() {
return new Iterator<String>() {
int item = 3;

@Override
public boolean hasNext() {
return item > 0;
}

@Override
public String next() {
item--;
return Integer.toString(item);
}
};
}
}

/*
/**********************************************************
/* Unit tests
/**********************************************************
*/

private final XmlMapper MAPPER = new XmlMapper();
private final XmlMapper MAPPER = newMapper();

public void testSimpleWrappedList() throws IOException
{
Expand All @@ -70,4 +94,11 @@ public void testStringList() throws IOException
+"<strings><text>c</text></strings>"
+"</stringList></StringListBean>", xml);
}

// [dataformat-xml#148]
public void testIteratorSerialization() throws Exception
{
assertEquals("<Bean148><item>2</item><item>1</item><item>0</item></Bean148>",
MAPPER.writeValueAsString(new Bean148()).trim());
}
}

0 comments on commit 6c46d9b

Please sign in to comment.