Package org.mongojack

Class 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 by BeanDeserializer.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 Detail

      • writeNullAsNull

        protected final boolean writeNullAsNull
    • Constructor Detail

      • TransformingEmbeddedObjectSerializer

        protected TransformingEmbeddedObjectSerializer()
      • TransformingEmbeddedObjectSerializer

        protected TransformingEmbeddedObjectSerializer​(boolean writeNullAsNull)
    • Method Detail

      • 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 class com.fasterxml.jackson.databind.JsonSerializer<InputType>
        Throws:
        IOException