Skip to content

Commit 53766e8

Browse files
author
Pascal Gélinas
committed
Fixes FasterXML#81. Requires FasterXML/jackson-databind#394 to compile.
1 parent 5ba7db7 commit 53766e8

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;
@@ -256,6 +257,11 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
256257
TypeSerializer typeSer)
257258
throws IOException, JsonGenerationException
258259
{
260+
if (_objectIdWriter != null) {
261+
_serializeWithObjectId(bean, jgen, provider, typeSer);
262+
return;
263+
}
264+
259265
/* Ok: let's serialize type id as attribute, but if (and only if!)
260266
* we are using AS_PROPERTY
261267
*/
@@ -271,6 +277,28 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
271277
}
272278
}
273279

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

0 commit comments

Comments
 (0)