Skip to content

Commit 424df53

Browse files
authored
Fix issue wrt [databind#2780] change (#803)
1 parent 814c54a commit 424df53

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/main/java/tools/jackson/dataformat/xml/ser/XmlBeanSerializerBase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ public void serializeWithType(Object bean, JsonGenerator gen, SerializationConte
307307
throws JacksonException
308308
{
309309
if (_objectIdWriter != null) {
310+
// [dataformat-xml#81]: XML cannot represent typed object id references
311+
// as arrays ([type, id]) inline within lists, unlike JSON. So for
312+
// back-references, write just the id without type wrapping.
313+
WritableObjectId oid = ctxt.findObjectId(bean, _objectIdWriter.generator);
314+
if (oid.writeAsReference(gen, ctxt, _objectIdWriter)) {
315+
return;
316+
}
310317
_serializeWithObjectId(bean, gen, ctxt, typeSer);
311318
return;
312319
}

src/test/java/tools/jackson/dataformat/xml/misc/PolymorphicTypesTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
public class PolymorphicTypesTest extends XmlTestUtil
1616
{
1717
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY)
18-
static class BaseTypeWithClassProperty { }
18+
public static class BaseTypeWithClassProperty { }
1919

20-
static class SubTypeWithClassProperty extends BaseTypeWithClassProperty {
20+
public static class SubTypeWithClassProperty extends BaseTypeWithClassProperty {
2121
public String name;
2222

2323
public SubTypeWithClassProperty() { }
2424
public SubTypeWithClassProperty(String s) { name = s; }
2525
}
2626

2727
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.WRAPPER_OBJECT)
28-
protected static class BaseTypeWithClassObject { }
28+
public static class BaseTypeWithClassObject { }
2929

30-
protected static class SubTypeWithClassObject extends BaseTypeWithClassObject {
30+
public static class SubTypeWithClassObject extends BaseTypeWithClassObject {
3131
public String name;
3232

3333
public SubTypeWithClassObject() { }
@@ -36,14 +36,14 @@ public SubTypeWithClassObject() { }
3636

3737
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)
3838
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
39-
protected static class TypeWithClassPropertyAndObjectId {
39+
public static class TypeWithClassPropertyAndObjectId {
4040
public String id;
4141

4242
public TypeWithClassPropertyAndObjectId() {}
4343
public TypeWithClassPropertyAndObjectId(String id) { this.id = id; }
4444
}
4545

46-
protected static class Wrapper {
46+
public static class Wrapper {
4747
public List<TypeWithClassPropertyAndObjectId> data;
4848

4949
public Wrapper(){}

0 commit comments

Comments
 (0)