forked from FasterXML/jackson-dataformat-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for FasterXML#336, multiple class adapted for the feature.
- Accepts new annotation for collection type.
- Loading branch information
perilbrain
committed
Aug 17, 2019
1 parent
6bd59fb
commit 7c0a367
Showing
8 changed files
with
150 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ target | |
*.iml | ||
*.ipr | ||
*.iws | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/com/fasterxml/jackson/dataformat/xml/ser/TestSerializationCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.fasterxml.jackson.dataformat.xml.ser; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
public class TestSerializationCollection extends XmlTestBase { | ||
|
||
|
||
@JacksonXmlRootElement(localName="person", namespace="http://example.org/person", wrapperForIndexedType = "Person") | ||
static class Person { | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
public Integer id; | ||
|
||
public String n; | ||
|
||
public Person(Integer id, String name) { | ||
this.id = id; | ||
this.n = name; | ||
} | ||
} | ||
|
||
@JacksonXmlRootElement(localName = "persons") | ||
static class PersonList extends ArrayList<Person>{} | ||
|
||
public void testList() throws Exception | ||
{ | ||
List<String> personNames = Arrays.asList("A", "B", "C"); | ||
PersonList personList = IntStream.range(0, personNames.size()) | ||
.mapToObj(count -> new Person(count, personNames.get(count))) | ||
.collect(Collectors.toCollection(PersonList::new)); | ||
XmlMapper xmlMapper = new XmlMapper(); | ||
String xml = xmlMapper.writeValueAsString(personList); | ||
assertEquals("<persons><Person id=\"0\"><n>A</n></Person><Person id=\"1\"><n>B</n></Person><Person id=\"2\"><n>C</n></Person></persons>", | ||
xml); | ||
} | ||
} |