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
IllegalArgumentExceptionwith 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 booleanwriteNullAsNull
-
Constructor Summary
Constructors Modifier Constructor Description protectedTransformingEmbeddedObjectSerializer()protectedTransformingEmbeddedObjectSerializer(boolean writeNullAsNull)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidserialize(InputType value, com.fasterxml.jackson.core.JsonGenerator jgen, com.fasterxml.jackson.databind.SerializerProvider provider)protected abstract TransformedTypetransform(InputType value)Transform to the desired type.protected voidwriteEmbeddedObject(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:
serializein classcom.fasterxml.jackson.databind.JsonSerializer<InputType>- Throws:
IOException
-
-