org.codehaus.jackson.map.ser
Class JsonValueSerializer

java.lang.Object
  extended by org.codehaus.jackson.map.JsonSerializer<Object>
      extended by org.codehaus.jackson.map.ser.JsonValueSerializer
All Implemented Interfaces:
ResolvableSerializer, SchemaAware

public final class JsonValueSerializer
extends JsonSerializer<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
 
Constructor Summary
JsonValueSerializer(Method valueMethod, JsonSerializer<Object> ser)
           
 
Method Summary
 JsonNode getSchema(SerializerProvider provider, Type typeHint)
          Get the representation of the schema to which this serializer will conform.
 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.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonValueSerializer

public JsonValueSerializer(Method valueMethod,
                           JsonSerializer<Object> ser)
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 JsonSerializer<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

getSchema

public JsonNode getSchema(SerializerProvider provider,
                          Type typeHint)
                   throws JsonMappingException
Description copied from interface: SchemaAware
Get the representation of the schema to which this serializer will conform.

Specified by:
getSchema in interface SchemaAware
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

toString

public String toString()
Overrides:
toString in class Object