-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
764c97a
commit 0bf4017
Showing
4 changed files
with
213 additions
and
3 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
80 changes: 80 additions & 0 deletions
80
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/DeserializePolyList178Test.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,80 @@ | ||
package com.fasterxml.jackson.dataformat.xml.failing; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
|
||
public class DeserializePolyList178Test extends XmlTestBase | ||
{ | ||
static class Company { | ||
public List<Computer> computers; | ||
|
||
public Company() { | ||
computers = new ArrayList<Computer>(); | ||
} | ||
|
||
public Company add(Computer computer) { | ||
if (computers == null) { | ||
computers = new ArrayList<Computer>(); | ||
} | ||
computers.add(computer); | ||
return this; | ||
} | ||
} | ||
|
||
// 02-Jan-2015, tatu: Does not seem to matter; was included in the original reproduction | ||
// @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.WRAPPER_OBJECT, | ||
property = "type") | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = DesktopComputer.class, name = "desktop"), | ||
@JsonSubTypes.Type(value = LaptopComputer.class, name = "laptop") | ||
}) | ||
static class Computer { | ||
public String id; | ||
} | ||
|
||
@JsonTypeName("desktop") | ||
static class DesktopComputer extends Computer { | ||
public String location; | ||
|
||
protected DesktopComputer() { } | ||
public DesktopComputer with(String id0, String l) { | ||
id = id0; | ||
location = l; | ||
return this; | ||
} | ||
} | ||
|
||
@JsonTypeName("laptop") | ||
static class LaptopComputer extends Computer { | ||
public String vendor; | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests | ||
/********************************************************** | ||
*/ | ||
|
||
private final XmlMapper MAPPER = new XmlMapper(); | ||
|
||
// for [dataformat-xml#178] | ||
public void testPolyIdList178() throws Exception | ||
{ | ||
Company input = new Company(); | ||
input.add(new DesktopComputer().with("1", "http://foo.com")); | ||
input.add(new DesktopComputer().with("2", "http://bar.com")); | ||
String xml = MAPPER.writerWithDefaultPrettyPrinter() | ||
.writeValueAsString(input); | ||
//System.out.println("XML:\n"+xml); | ||
|
||
Company result = MAPPER.readValue(xml, Company.class); | ||
assertNotNull(result.computers); | ||
assertEquals(2, result.computers.size()); | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/JAXBObjectId170Test.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,125 @@ | ||
package com.fasterxml.jackson.dataformat.xml.failing; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.xml.bind.annotation.*; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import com.fasterxml.jackson.databind.AnnotationIntrospector; | ||
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; | ||
import com.fasterxml.jackson.dataformat.xml.XmlAnnotationIntrospector; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
import com.fasterxml.jackson.dataformat.xml.jaxb.XmlJaxbAnnotationIntrospector; | ||
|
||
public class JAXBObjectId170Test extends XmlTestBase | ||
{ | ||
static class Company { | ||
public List<Computer> computers; | ||
public List<Employee> employees; | ||
|
||
public Company() { | ||
computers = new ArrayList<Computer>(); | ||
} | ||
|
||
public Company add(Computer computer) { | ||
if (computers == null) { | ||
computers = new ArrayList<Computer>(); | ||
} | ||
computers.add(computer); | ||
return this; | ||
} | ||
} | ||
|
||
@XmlType(name = "employee") | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
static class Employee { | ||
@XmlAttribute | ||
@XmlID | ||
public String id; | ||
|
||
@XmlAttribute | ||
public String name; | ||
|
||
@XmlIDREF | ||
public Computer computer; | ||
} | ||
|
||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.WRAPPER_OBJECT, | ||
property = "type") | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = DesktopComputer.class, name = "desktop"), | ||
@JsonSubTypes.Type(value = LaptopComputer.class, name = "laptop") | ||
}) | ||
static class Computer { | ||
public String id; | ||
} | ||
|
||
static class DesktopComputer extends Computer { | ||
public String location; | ||
|
||
protected DesktopComputer() { } | ||
public DesktopComputer with(String id0, String l) { | ||
id = id0; | ||
location = l; | ||
return this; | ||
} | ||
} | ||
|
||
static class LaptopComputer extends Computer { | ||
public String vendor; | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests | ||
/********************************************************** | ||
*/ | ||
|
||
// for [dataformat-xml#178] | ||
public void testPolyIdList178() throws Exception | ||
{ | ||
final String XML = | ||
"<company>\n"+ | ||
"<computers>\n"+ | ||
" <computers>\n"+ | ||
" <desktop id='computer-1'>\n"+ | ||
" <location>Bangkok</location>\n"+ | ||
" </desktop>\n"+ | ||
" </computers>\n"+ | ||
" <computers>\n"+ | ||
" <desktop id='computer-2'>\n"+ | ||
" <location>Pattaya</location>\n"+ | ||
" </desktop>\n"+ | ||
" </computers>\n"+ | ||
" <computers>\n"+ | ||
" <laptop id='computer-3'>\n"+ | ||
" <vendor>Apple</vendor>\n"+ | ||
" </laptop>\n"+ | ||
" </computers>\n"+ | ||
" </computers>\n"+ | ||
" <employees>\n"+ | ||
" <employee id='emp-1' name='Robert Patrick'>\n"+ | ||
" <computer>computer-3</computer>\n"+ | ||
" </employee>\n"+ | ||
" <employee id='emp-2' name='Michael Smith'>\n"+ | ||
" <computer>computer-2</computer>\n"+ | ||
" </employee>\n"+ | ||
" </employees>\n"+ | ||
"</company>\n" | ||
; | ||
|
||
XmlMapper mapper = new XmlMapper(); | ||
AnnotationIntrospector intr = XmlAnnotationIntrospector.Pair.instance | ||
(new XmlJaxbAnnotationIntrospector(mapper.getTypeFactory()), new JacksonAnnotationIntrospector()); | ||
mapper.setAnnotationIntrospector(intr); | ||
// should be default but doesn't seem to be? | ||
mapper.setDefaultUseWrapper(true); | ||
|
||
Company result = mapper.readValue(XML, Company.class); | ||
assertNotNull(result); | ||
} | ||
} |
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