Package org.mongojack
Class TransformingEmbeddedObjectSerializer<InputType,TransformedType>
- java.lang.Object
-
- com.fasterxml.jackson.databind.JsonSerializer<InputType>
-
- org.mongojack.TransformingEmbeddedObjectSerializer<InputType,TransformedType>
-
- All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
- Direct Known Subclasses:
EmbeddedObjectSerializer
,MongoJackInstantSerializer
public abstract class TransformingEmbeddedObjectSerializer<InputType,TransformedType> extends com.fasterxml.jackson.databind.JsonSerializer<InputType>
Safe embedded object serializer.When used with BsonObjectGenerator or DBEncoderBsonGenerator, passes values straight through.
When used with a
TokenBuffer
(as byBeanDeserializer.deserializeWithUnwrapped(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
), temporarily clears the TokenBuffer codec before passing the value through, so it will be properly serialized as an embedded object. (Failure to do so would blow up the stack, as the TokenBuffer would pass the object right back to the ObjectMapper.)When used with other JsonSerializers, throws
IllegalArgumentException
with a message that it's designed for use only with BsonObjectGenerator or DBEncoderBsonGenerator or TokenBuffer.- Since:
- 3.0.4
- Author:
- Kevin D. Keck
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
writeNullAsNull
-
Constructor Summary
Constructors Modifier Constructor Description protected
TransformingEmbeddedObjectSerializer()
protected
TransformingEmbeddedObjectSerializer(boolean writeNullAsNull)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
serialize(InputType value, com.fasterxml.jackson.core.JsonGenerator jgen, com.fasterxml.jackson.databind.SerializerProvider provider)
protected abstract TransformedType
transform(InputType value)
Transform to the desired type.protected void
writeEmbeddedObject(TransformedType value, com.fasterxml.jackson.core.JsonGenerator jgen)
-
-
-
Method Detail
-
writeEmbeddedObject
protected void writeEmbeddedObject(TransformedType value, com.fasterxml.jackson.core.JsonGenerator jgen) throws IOException
- Throws:
IOException
-
transform
protected abstract TransformedType transform(InputType value)
Transform to the desired type. Careful of nulls!- Parameters:
value
-- Returns:
-
serialize
public void serialize(InputType value, com.fasterxml.jackson.core.JsonGenerator jgen, com.fasterxml.jackson.databind.SerializerProvider provider) throws IOException
- Specified by:
serialize
in classcom.fasterxml.jackson.databind.JsonSerializer<InputType>
- Throws:
IOException
-
-