org.codehaus.jackson.map.ser.std

## Class JsonValueSerializer

- java.lang.Object
- - org.codehaus.jackson.map.JsonSerializer<T>
  - - org.codehaus.jackson.map.ser.std.SerializerBase<Object>
    - - org.codehaus.jackson.map.ser.std.JsonValueSerializer

- All Implemented Interfaces:
    ResolvableSerializer, SchemaAware

      public class JsonValueSerializer
      extends SerializerBase<Object>
      implements ResolvableSerializer, SchemaAware

  Serializer class that can serialize Object that have a `JsonValue` annotation to indicate that serialization should be done by calling the method annotated, and serializing result it returns.

  Implementation note: we will post-process resulting serializer (much like what is done with `BeanSerializer`) to figure out actual serializers for final types. This must be done from `resolve(org.codehaus.jackson.map.SerializerProvider)` method, and NOT from constructor; otherwise we could end up with an infinite loop.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.codehaus.jackson.map.JsonSerializer

      `JsonSerializer.None`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Method` | `_accessorMethod`
    `protected boolean` | `_forceTypeInformation` This is a flag that is set in rare (?) cases where this serializer is used for "natural" types (boolean, int, String, double); and where we actually must force type information wrapping, even though one would not normally be added.
    `protected BeanProperty` | `_property`
    `protected JsonSerializer<Object>` | `_valueSerializer`

    - ### Fields inherited from class org.codehaus.jackson.map.ser.std.SerializerBase

      `_handledType`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsonValueSerializer(Method valueMethod, JsonSerializer<Object> ser, BeanProperty property)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `JsonNode` | `getSchema(SerializerProvider provider, Type typeHint)` Note: since Jackson 1.9, default implementation claims type is "string"
    `protected boolean` | `isNaturalTypeWithStdHandling(JavaType type, JsonSerializer<?> ser)`
    `void` | `resolve(SerializerProvider provider)` We can try to find the actual serializer for value, if we can statically figure out what the result type must be.
    `void` | `serialize(Object bean, JsonGenerator jgen, SerializerProvider prov)` Method that can be called to ask implementation to serialize values of type this serializer handles.
    `void` | `serializeWithType(Object bean, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer)` Method that can be called to ask implementation to serialize values of type this serializer handles, using specified type serializer for embedding necessary type information.
    `String` | `toString()`

    - ### Methods inherited from class org.codehaus.jackson.map.ser.std.SerializerBase

      `createObjectNode, createSchemaNode, createSchemaNode, handledType, isDefaultSerializer, wrapAndThrow, wrapAndThrow, wrapAndThrow, wrapAndThrow`

    - ### Methods inherited from class org.codehaus.jackson.map.JsonSerializer

      `isUnwrappingSerializer, unwrappingSerializer`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### _accessorMethod

          protected final Method _accessorMethod

    - #### _valueSerializer

          protected JsonSerializer<Object> _valueSerializer

    - #### _property

          protected final BeanProperty _property

    - #### _forceTypeInformation

          protected boolean _forceTypeInformation

      This is a flag that is set in rare (?) cases where this serializer is used for "natural" types (boolean, int, String, double); and where we actually must force type information wrapping, even though one would not normally be added.
      Since:
        1.7

  - ### Constructor Detail

    - #### JsonValueSerializer

          public JsonValueSerializer(Method valueMethod,
                             JsonSerializer<Object> ser,
                             BeanProperty property)

      Parameters:
        `ser` - Explicit serializer to use, if caller knows it (which occurs if and only if the "value method" was annotated with `JsonSerialize.using()`), otherwise null

  - ### Method Detail

    - #### serialize

          public void serialize(Object bean,
                       JsonGenerator jgen,
                       SerializerProvider prov)
                         throws IOException,
                                JsonGenerationException

      Description copied from class: `JsonSerializer`
      Method that can be called to ask implementation to serialize values of type this serializer handles.
      Specified by:
        `serialize` in class `SerializerBase<Object>`
      Parameters:
        `bean` - Value to serialize; can not be null.
        `jgen` - Generator used to output resulting Json content
        `prov` - Provider that can be used to get serializers for serializing Objects value contains, if any.
      Throws:
        `IOException`
        `JsonGenerationException`

    - #### serializeWithType

          public void serializeWithType(Object bean,
                               JsonGenerator jgen,
                               SerializerProvider provider,
                               TypeSerializer typeSer)
                                 throws IOException,
                                        JsonProcessingException

      Description copied from class: `JsonSerializer`
      Method that can be called to ask implementation to serialize values of type this serializer handles, using specified type serializer for embedding necessary type information.

      Default implementation will ignore serialization of type information, and just calls `JsonSerializer.serialize(T, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.map.SerializerProvider)`: serializers that can embed type information should override this to implement actual handling. Most common such handling is done by something like:

            // note: method to call depends on whether this type is serialized as JSON scalar, object or Array!
            typeSer.writeTypePrefixForScalar(value, jgen);
            serialize(value, jgen, provider);
            typeSer.writeTypeSuffixForScalar(value, jgen);

      Overrides:
        `serializeWithType` in class `JsonSerializer<Object>`
      Parameters:
        `bean` - Value to serialize; can not be null.
        `jgen` - Generator used to output resulting Json content
        `provider` - Provider that can be used to get serializers for serializing Objects value contains, if any.
        `typeSer` - Type serializer to use for including type information
      Throws:
        `IOException`
        `JsonProcessingException`

    - #### getSchema

          public JsonNode getSchema(SerializerProvider provider,
                           Type typeHint)
                             throws JsonMappingException

      Description copied from class: `SerializerBase`
      Note: since Jackson 1.9, default implementation claims type is "string"
      Specified by:
        `getSchema` in interface `SchemaAware`
      Overrides:
        `getSchema` in class `SerializerBase<Object>`
      Parameters:
        `provider` - The serializer provider.
        `typeHint` - A hint about the type.
      Returns:
        Json-schema for this serializer.
      Throws:
        `JsonMappingException`

    - #### resolve

          public void resolve(SerializerProvider provider)
                       throws JsonMappingException

      We can try to find the actual serializer for value, if we can statically figure out what the result type must be.
      Specified by:
        `resolve` in interface `ResolvableSerializer`
      Parameters:
        `provider` - Provider that has constructed serializer this method is called on.
      Throws:
        `JsonMappingException`

    - #### isNaturalTypeWithStdHandling

          protected boolean isNaturalTypeWithStdHandling(JavaType type,
                                             JsonSerializer<?> ser)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`