Skip to content

Commit af3fee5

Browse files
author
Pascal Gélinas
committed
Moved test case for issue #81 from failing to package to test package.
1 parent 62b87e1 commit af3fee5

2 files changed

Lines changed: 40 additions & 39 deletions

File tree

src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TestPolymorphic.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package com.fasterxml.jackson.dataformat.xml.failing;
22

3-
import java.util.*;
4-
5-
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
63
import com.fasterxml.jackson.annotation.JsonTypeInfo;
7-
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
8-
import com.fasterxml.jackson.dataformat.xml.*;
4+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
5+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
96

107
public class TestPolymorphic extends XmlTestBase
118
{
@@ -56,20 +53,6 @@ public ClassArrayWrapper() { }
5653
public ClassArrayWrapper(String s) { wrapped = new SubTypeWithClassArray(s); }
5754
}
5855

59-
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)
60-
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
61-
protected static class TypeWithClassPropertyAndObjectId {
62-
public String id;
63-
64-
public TypeWithClassPropertyAndObjectId(String id) { this.id = id; }
65-
}
66-
67-
protected static class Wrapper {
68-
public List<TypeWithClassPropertyAndObjectId> data;
69-
70-
public Wrapper(List<TypeWithClassPropertyAndObjectId> data) { this.data = data; }
71-
}
72-
7356
/*
7457
/**********************************************************
7558
/* Set up
@@ -114,22 +97,5 @@ public void testAsWrappedClassArray() throws Exception
11497
assertEquals(SubTypeWithClassArray.class, result.wrapped.getClass());
11598
assertEquals("Foobar", ((SubTypeWithClassArray) result.wrapped).name);
11699
}
117-
118-
/**
119-
* Test for issue 81
120-
*/
121-
public void testAsPropertyWithObjectId() throws Exception
122-
{
123-
List<TypeWithClassPropertyAndObjectId> data = new ArrayList<TestPolymorphic.TypeWithClassPropertyAndObjectId>();
124-
TypeWithClassPropertyAndObjectId object = new TypeWithClassPropertyAndObjectId("Foobar");
125-
data.add(object);
126-
// This will be written as an id reference instead of object; as such, no type info will be written.
127-
data.add(object);
128-
String xml = _xmlMapper.writeValueAsString(new Wrapper(data));
129-
Wrapper result = _xmlMapper.readValue(xml, Wrapper.class);
130-
assertNotNull(result);
131-
assertSame(result.data.get(0), result.data.get(1));
132-
assertEquals("Foobar", result.data.get(0).id);
133-
}
134100
}
135101

src/test/java/com/fasterxml/jackson/dataformat/xml/types/TestPolymorphic.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package com.fasterxml.jackson.dataformat.xml.types;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
37
import com.fasterxml.jackson.annotation.JsonTypeInfo;
8+
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
49
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
510
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
611

@@ -22,9 +27,6 @@ public SubTypeWithClassProperty() { }
2227
public SubTypeWithClassProperty(String s) { name = s; }
2328
}
2429

25-
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.WRAPPER_ARRAY)
26-
static class BaseTypeWithClassArray { }
27-
2830
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.WRAPPER_OBJECT)
2931
protected static class BaseTypeWithClassObject { }
3032

@@ -35,6 +37,22 @@ public SubTypeWithClassObject() { }
3537
public SubTypeWithClassObject(String s) { name = s; }
3638
}
3739

40+
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)
41+
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
42+
protected static class TypeWithClassPropertyAndObjectId {
43+
public String id;
44+
45+
public TypeWithClassPropertyAndObjectId() {}
46+
public TypeWithClassPropertyAndObjectId(String id) { this.id = id; }
47+
}
48+
49+
protected static class Wrapper {
50+
public List<TypeWithClassPropertyAndObjectId> data;
51+
52+
public Wrapper(){}
53+
public Wrapper(List<TypeWithClassPropertyAndObjectId> data) { this.data = data; }
54+
}
55+
3856
/*
3957
/**********************************************************
4058
/* Set up
@@ -85,5 +103,22 @@ public void testAsClassObject() throws Exception
85103
assertEquals(SubTypeWithClassObject.class, result.getClass());
86104
assertEquals("Foobar", ((SubTypeWithClassObject) result).name);
87105
}
106+
107+
/**
108+
* Test for issue 81
109+
*/
110+
public void testAsPropertyWithObjectId() throws Exception
111+
{
112+
List<TypeWithClassPropertyAndObjectId> data = new ArrayList<TestPolymorphic.TypeWithClassPropertyAndObjectId>();
113+
TypeWithClassPropertyAndObjectId object = new TypeWithClassPropertyAndObjectId("Foobar");
114+
data.add(object);
115+
// This will be written as an id reference instead of object; as such, no type info will be written.
116+
data.add(object);
117+
String xml = _xmlMapper.writeValueAsString(new Wrapper(data));
118+
Wrapper result = _xmlMapper.readValue(xml, Wrapper.class);
119+
assertNotNull(result);
120+
assertSame(result.data.get(0), result.data.get(1));
121+
assertEquals("Foobar", result.data.get(0).id);
122+
}
88123
}
89124

0 commit comments

Comments
 (0)