Class TransformingEmbeddedObjectSerializer<InputType, TransformedType>

java.lang.Object
tools.jackson.databind.ValueSerializer<InputType>
org.mongojack.TransformingEmbeddedObjectSerializer<InputType, TransformedType>
All Implemented Interfaces:
tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
Direct Known Subclasses:
EmbeddedObjectSerializer, MongoJackInstantSerializer

public abstract class TransformingEmbeddedObjectSerializer<InputType, TransformedType> extends tools.jackson.databind.ValueSerializer<InputType>
Safe embedded object serializer.

When used with BsonObjectGenerator or DBEncoderBsonGenerator, passes values straight through.

When used with a TokenBuffer (as by BeanDeserializer.deserializeWithUnwrapped(JsonParser, 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 ValueSerializers, 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
  • Nested Class Summary

    Nested classes/interfaces inherited from class tools.jackson.databind.ValueSerializer

    tools.jackson.databind.ValueSerializer.None
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final boolean
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    TransformingEmbeddedObjectSerializer(boolean writeNullAsNull)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    serialize(InputType value, tools.jackson.core.JsonGenerator jgen, tools.jackson.databind.SerializationContext provider)
     
    protected abstract TransformedType
    Transform to the desired type.
    protected void
    writeEmbeddedObject(TransformedType value, tools.jackson.core.JsonGenerator jgen)
     

    Methods inherited from class tools.jackson.databind.ValueSerializer

    acceptJsonFormatVisitor, createContextual, getDelegatee, handledType, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, resolve, serializeWithType, unwrappingSerializer, usesObjectId, withFilterId, withFormatOverrides, withIgnoredProperties

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • writeNullAsNull

      protected final boolean writeNullAsNull
  • Constructor Details

    • TransformingEmbeddedObjectSerializer

      protected TransformingEmbeddedObjectSerializer()
    • TransformingEmbeddedObjectSerializer

      protected TransformingEmbeddedObjectSerializer(boolean writeNullAsNull)
  • Method Details

    • writeEmbeddedObject

      protected void writeEmbeddedObject(TransformedType value, tools.jackson.core.JsonGenerator jgen) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • transform

      protected abstract TransformedType transform(InputType value)
      Transform to the desired type. Careful of nulls!
      Parameters:
      value -
      Returns:
    • serialize

      public void serialize(InputType value, tools.jackson.core.JsonGenerator jgen, tools.jackson.databind.SerializationContext provider) throws tools.jackson.core.JacksonException
      Specified by:
      serialize in class tools.jackson.databind.ValueSerializer<InputType>
      Throws:
      tools.jackson.core.JacksonException