Skip to content

Commit 62b87e1

Browse files
author
Pascal Gélinas
committed
Fixes #81. Requires FasterXML/jackson-databind#394 to compile.
1 parent 136e5d3 commit 62b87e1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/main/java/com/fasterxml/jackson/dataformat/xml/ser/XmlBeanSerializer.java

+28
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.fasterxml.jackson.databind.ser.BeanSerializer;
1313
import com.fasterxml.jackson.databind.ser.PropertyFilter;
1414
import com.fasterxml.jackson.databind.ser.impl.ObjectIdWriter;
15+
import com.fasterxml.jackson.databind.ser.impl.WritableObjectId;
1516
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
1617
import com.fasterxml.jackson.databind.util.NameTransformer;
1718
import com.fasterxml.jackson.dataformat.xml.util.XmlInfo;
@@ -249,6 +250,11 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
249250
TypeSerializer typeSer)
250251
throws IOException, JsonGenerationException
251252
{
253+
if (_objectIdWriter != null) {
254+
_serializeWithObjectId(bean, jgen, provider, typeSer);
255+
return;
256+
}
257+
252258
/* Ok: let's serialize type id as attribute, but if (and only if!)
253259
* we are using AS_PROPERTY
254260
*/
@@ -264,6 +270,28 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
264270
}
265271
}
266272

273+
@Override
274+
protected void _serializeObjectId(Object bean,
275+
JsonGenerator jgen,
276+
SerializerProvider provider,
277+
TypeSerializer typeSer,
278+
WritableObjectId objectId) throws IOException, JsonProcessingException,
279+
JsonGenerationException {
280+
/* Ok: let's serialize type id as attribute, but if (and only if!)
281+
* we are using AS_PROPERTY
282+
*/
283+
if (typeSer.getTypeInclusion() == JsonTypeInfo.As.PROPERTY) {
284+
ToXmlGenerator xgen = (ToXmlGenerator)jgen;
285+
xgen.setNextIsAttribute(true);
286+
super._serializeObjectId(bean, jgen, provider, typeSer, objectId);
287+
if (_attributeCount == 0) { // if no attributes, need to reset
288+
xgen.setNextIsAttribute(false);
289+
}
290+
} else {
291+
super._serializeObjectId(bean, jgen, provider, typeSer, objectId);
292+
}
293+
}
294+
267295
/*
268296
/**********************************************************
269297
/* Helper methods

0 commit comments

Comments
 (0)