Class SerializationContextExt

All Implemented Interfaces:
tools.jackson.core.ObjectWriteContext
Direct Known Subclasses:
SerializationContextExt.Impl

public class SerializationContextExt extends SerializationContext
Extension over SerializationContext that adds methods needed by ObjectMapper (and ObjectWriter) but that are not to be exposed as general context during serialization.

Also note that all custom SerializationContext implementations must sub-class this class: ObjectMapper requires this type, not basic provider type.

  • Field Details

    • _seenObjectIds

      protected transient Map<Object,WritableObjectId> _seenObjectIds
      Per-serialization map Object Ids that have seen so far, iff Object Id handling is enabled.
    • _objectIdGenerators

      protected transient ArrayList<ObjectIdGenerator<?>> _objectIdGenerators
  • Constructor Details

  • Method Details

    • serializerInstance

      public ValueSerializer<Object> serializerInstance(Annotated annotated, Object serDef)
      Description copied from class: SerializationContext
      Method that can be called to construct and configure serializer instance, either given a Class to instantiate (with default constructor), or an uninitialized serializer instance. Either way, serializer will be properly resolved (via ValueSerializer.resolve(tools.jackson.databind.SerializationContext)).
      Specified by:
      serializerInstance in class SerializationContext
      Parameters:
      annotated - Annotated entity that contained definition
      serDef - Serializer definition: either an instance or class
    • includeFilterInstance

      public Object includeFilterInstance(BeanPropertyDefinition forProperty, Class<?> filterClass)
      Description copied from class: SerializationContext
      Method that can be called to construct and configure JsonInclude filter instance, given a Class to instantiate (with default constructor, by default).
      Specified by:
      includeFilterInstance in class SerializationContext
      Parameters:
      forProperty - (optional) If filter is created for a property, that property; `null` if filter created via defaulting, global or per-type.
    • includeFilterSuppressNulls

      public boolean includeFilterSuppressNulls(Object filter)
      Description copied from class: SerializationContext
      Follow-up method that may be called after calling SerializationContext.includeFilterInstance(tools.jackson.databind.introspect.BeanPropertyDefinition, java.lang.Class<?>), to check handling of `null` values by the filter.
      Specified by:
      includeFilterSuppressNulls in class SerializationContext
    • valueToTree

      public <T extends JsonNode> T valueToTree(Object fromValue) throws tools.jackson.core.JacksonException
      Method that will convert given Java value (usually bean) into its equivalent Tree model JsonNode representation. Functionally similar to serializing value into token stream and parsing that stream back as tree model node, but more efficient as TokenBuffer is used to contain the intermediate representation instead of fully serialized contents.

      NOTE: while results are usually identical to that of serialization followed by deserialization, this is not always the case. In some cases serialization into intermediate representation will retain encapsulation of things like raw value (RawValue) or basic node identity (JsonNode). If so, result is a valid tree, but values are not re-constructed through actual format representation. So if transformation requires actual materialization of encoded content, it will be necessary to do actual serialization.

      Specified by:
      valueToTree in class SerializationContext
      Type Parameters:
      T - Actual node type; usually either basic JsonNode or ObjectNode
      Parameters:
      fromValue - Java value to convert
      Returns:
      (non-null) Root node of the resulting content tree: in case of null value node for which JsonNode.isNull() returns true.
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • findObjectId

      public WritableObjectId findObjectId(Object forPojo, ObjectIdGenerator<?> generatorType)
      Description copied from class: SerializationContext
      Method called to find the Object Id for given POJO, if one has been generated. Will always return a non-null Object; contents vary depending on whether an Object Id already exists or not.
      Specified by:
      findObjectId in class SerializationContext
    • _createObjectIdMap

      protected Map<Object,WritableObjectId> _createObjectIdMap()
      Overridable helper method used for creating Map used for storing mappings from serializable objects to their Object Ids.
    • getGenerator

      public tools.jackson.core.JsonGenerator getGenerator()
      Accessor for the JsonGenerator currently in use for serializing content. Null for blueprint instances; non-null for actual active provider instances.
      Overrides:
      getGenerator in class SerializationContext
    • serializeValue

      public void serializeValue(tools.jackson.core.JsonGenerator gen, Object value) throws tools.jackson.core.JacksonException
      The method to be called by ObjectMapper and ObjectWriter for serializing given value, using serializers that this provider has access to (via caching and/or creating new serializers as need be).
      Throws:
      tools.jackson.core.JacksonException
    • serializeValue

      public void serializeValue(tools.jackson.core.JsonGenerator gen, Object value, JavaType rootType) throws tools.jackson.core.JacksonException
      The method to be called by ObjectMapper and ObjectWriter for serializing given value (assumed to be of specified root type, instead of runtime type of value), using serializers that this provider has access to (via caching and/or creating new serializers as need be),
      Parameters:
      rootType - Type to use for locating serializer to use, instead of actual runtime type. Must be actual type, or one of its super types
      Throws:
      tools.jackson.core.JacksonException
    • serializeValue

      public void serializeValue(tools.jackson.core.JsonGenerator gen, Object value, JavaType rootType, ValueSerializer<Object> ser) throws tools.jackson.core.JacksonException
      The method to be called by ObjectWriter for serializing given value (assumed to be of specified root type, instead of runtime type of value), when it may know specific ValueSerializer to use.
      Parameters:
      rootType - Type to use for locating serializer to use, instead of actual runtime type, if no serializer is passed
      ser - Root Serializer to use, if not null
      Throws:
      tools.jackson.core.JacksonException
    • serializePolymorphic

      public void serializePolymorphic(tools.jackson.core.JsonGenerator gen, Object value, JavaType rootType, ValueSerializer<Object> valueSer, TypeSerializer typeSer) throws tools.jackson.core.JacksonException
      Alternate serialization call used for polymorphic types, when TypeSerializer is already known, but the actual serializer may or may not be.
      Throws:
      tools.jackson.core.JacksonException
    • _serializeNull

      protected void _serializeNull(tools.jackson.core.JsonGenerator gen) throws tools.jackson.core.JacksonException
      Helper method called when root value to serialize is null
      Throws:
      tools.jackson.core.JacksonException
    • acceptJsonFormatVisitor

      public void acceptJsonFormatVisitor(JavaType javaType, JsonFormatVisitorWrapper visitor)
      The method to be called by ObjectMapper and ObjectWriter to expose the format of the given type to the given visitor
      Parameters:
      javaType - The type for which to generate format
      visitor - the visitor to accept the format