Package org.mongojack.internal
Class EmbeddedObjectSerializer<T>
- java.lang.Object
-
- com.fasterxml.jackson.databind.JsonSerializer<InputType>
-
- org.mongojack.TransformingEmbeddedObjectSerializer<T,T>
-
- org.mongojack.internal.EmbeddedObjectSerializer<T>
-
- All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
- Direct Known Subclasses:
CalendarSerializer
,DateSerializer
,ObjectIdSerializer
public abstract class EmbeddedObjectSerializer<T> extends TransformingEmbeddedObjectSerializer<T,T>
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 inherited from class org.mongojack.TransformingEmbeddedObjectSerializer
writeNullAsNull
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
EmbeddedObjectSerializer()
protected
EmbeddedObjectSerializer(boolean writeNullAsNull)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
serialize(T value, com.fasterxml.jackson.core.JsonGenerator jgen, com.fasterxml.jackson.databind.SerializerProvider provider)
protected T
transform(T value)
Transform to the desired type.protected void
writeEmbeddedObject(T value, com.fasterxml.jackson.core.JsonGenerator jgen)
-
-
-
Method Detail
-
transform
protected T transform(T value)
Description copied from class:TransformingEmbeddedObjectSerializer
Transform to the desired type. Careful of nulls!- Specified by:
transform
in classTransformingEmbeddedObjectSerializer<T,T>
- Returns:
-
writeEmbeddedObject
protected void writeEmbeddedObject(T value, com.fasterxml.jackson.core.JsonGenerator jgen) throws IOException
- Overrides:
writeEmbeddedObject
in classTransformingEmbeddedObjectSerializer<T,T>
- Throws:
IOException
-
serialize
public void serialize(T value, com.fasterxml.jackson.core.JsonGenerator jgen, com.fasterxml.jackson.databind.SerializerProvider provider) throws IOException
- Overrides:
serialize
in classTransformingEmbeddedObjectSerializer<T,T>
- Throws:
IOException
-
-