Skip to content

Commit

Permalink
Fixes FasterXML#81. Requires FasterXML/jackson-databind#394 to compile.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Gélinas committed Jan 28, 2014
1 parent 136e5d3 commit 62b87e1
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fasterxml.jackson.databind.ser.BeanSerializer;
import com.fasterxml.jackson.databind.ser.PropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.ObjectIdWriter;
import com.fasterxml.jackson.databind.ser.impl.WritableObjectId;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.NameTransformer;
import com.fasterxml.jackson.dataformat.xml.util.XmlInfo;
Expand Down Expand Up @@ -249,6 +250,11 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
TypeSerializer typeSer)
throws IOException, JsonGenerationException
{
if (_objectIdWriter != null) {
_serializeWithObjectId(bean, jgen, provider, typeSer);
return;
}

/* Ok: let's serialize type id as attribute, but if (and only if!)
* we are using AS_PROPERTY
*/
Expand All @@ -264,6 +270,28 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
}
}

@Override
protected void _serializeObjectId(Object bean,
JsonGenerator jgen,
SerializerProvider provider,
TypeSerializer typeSer,
WritableObjectId objectId) throws IOException, JsonProcessingException,
JsonGenerationException {
/* Ok: let's serialize type id as attribute, but if (and only if!)
* we are using AS_PROPERTY
*/
if (typeSer.getTypeInclusion() == JsonTypeInfo.As.PROPERTY) {
ToXmlGenerator xgen = (ToXmlGenerator)jgen;
xgen.setNextIsAttribute(true);
super._serializeObjectId(bean, jgen, provider, typeSer, objectId);
if (_attributeCount == 0) { // if no attributes, need to reset
xgen.setNextIsAttribute(false);
}
} else {
super._serializeObjectId(bean, jgen, provider, typeSer, objectId);
}
}

/*
/**********************************************************
/* Helper methods
Expand Down

0 comments on commit 62b87e1

Please sign in to comment.