Skip to content

Commit a55e73c

Browse files
committed
Fix #169 (actual main fix in jackson-databind)
1 parent cd3129c commit a55e73c

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
2525
</scm>
2626
<properties>
2727
<version.jackson.annotations>2.7.0-rc2</version.jackson.annotations>
28-
<version.jackson.core>2.7.0-rc2</version.jackson.core>
29-
<version.jackson.jaxb>${version.jackson.core}</version.jackson.jaxb>
28+
<version.jackson.core>2.7.0-rc3-SNAPSHOT</version.jackson.core>
29+
<version.jackson.jaxb>2.7.0-rc2</version.jackson.jaxb>
3030
<packageVersion.dir>com/fasterxml/jackson/dataformat/xml</packageVersion.dir>
3131
<packageVersion.package>${project.groupId}.xml</packageVersion.package>
3232

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Project: jackson-dataformat-xml
77
2.7.0 (not yet released)
88

99
#156: Add `XmlMapper.setDefaultUseWrapper()` for convenience.
10+
#169: Fail to deserialize "empty" polymorphic classes
1011

1112
2.6.4 (not yet released)
1213

src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void setXMLTextElementName(String name) {
203203
*/
204204
@Override
205205
public boolean requiresCustomCodec() {
206-
return false;
206+
return true;
207207
}
208208

209209
/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.fasterxml.jackson.dataformat.xml.misc;
2+
3+
import com.fasterxml.jackson.annotation.*;
4+
5+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
6+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
7+
8+
// test(s) for [dataformat-xml#111]
9+
public class EmptyPolymorphicTest extends XmlTestBase
10+
{
11+
static class Data {
12+
public String name;
13+
14+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
15+
@JsonSubTypes({ @JsonSubTypes.Type(EmptyProxy.class) })
16+
public Proxy proxy;
17+
18+
public Data() { }
19+
public Data(String n) {
20+
name = n;
21+
proxy = new EmptyProxy();
22+
}
23+
}
24+
25+
static interface Proxy { }
26+
27+
@JsonTypeName("empty")
28+
static class EmptyProxy implements Proxy { }
29+
30+
/*
31+
/**********************************************************
32+
/* Test methods
33+
/**********************************************************
34+
*/
35+
36+
protected XmlMapper MAPPER = new XmlMapper();
37+
38+
public void testEmpty() throws Exception
39+
{
40+
String xml = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(new Data("Foobar"));
41+
System.out.println("XML:\n"+xml);
42+
final Data data = MAPPER.readValue(xml, Data.class);
43+
// "<data><name>Foobar</name><proxy><empty></empty></proxy></data>"
44+
assertNotNull(data);
45+
}
46+
}

src/test/java/com/fasterxml/jackson/dataformat/xml/misc/PolymorphicTypesTest.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static class SubTypeWithClassProperty extends BaseTypeWithClassProperty {
2626
public SubTypeWithClassProperty() { }
2727
public SubTypeWithClassProperty(String s) { name = s; }
2828
}
29-
29+
3030
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.WRAPPER_OBJECT)
3131
protected static class BaseTypeWithClassObject { }
3232

@@ -67,7 +67,7 @@ public void setUp() throws Exception {
6767
super.setUp();
6868
_xmlMapper = new XmlMapper();
6969
}
70-
70+
7171
/*
7272
/**********************************************************
7373
/* Unit tests
@@ -79,9 +79,6 @@ public void testAsClassProperty() throws Exception
7979
String xml = _xmlMapper.writeValueAsString(new SubTypeWithClassProperty("Foobar"));
8080

8181
// Type info should be written as an attribute, so:
82-
/* 13-Jan-2010, tatu: With Jackson 1.7.1, it is possible to override type information
83-
* inclusion, which allows use of attribute over element, so:
84-
*/
8582
final String exp =
8683
"<SubTypeWithClassProperty _class=\"com.fasterxml.jackson.dataformat.xml.misc.PolymorphicTypesTest..SubTypeWithClassProperty\">"
8784
//"<SubTypeWithClassProperty><_class>com.fasterxml.jackson.xml.types.TestPolymorphic..SubTypeWithClassProperty</_class>"
@@ -105,7 +102,7 @@ public void testAsClassObject() throws Exception
105102
}
106103

107104
/**
108-
* Test for issue 81
105+
* Test for [dataformat-xml#81]
109106
*/
110107
public void testAsPropertyWithObjectId() throws Exception
111108
{

0 commit comments

Comments
 (0)