org.codehaus.jackson.map.ser
Class JsonValueSerializer

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

public final class JsonValueSerializer
extends JsonSerializer<java.lang.Object>
implements ResolvableSerializer

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.


Constructor Summary
JsonValueSerializer(java.lang.reflect.Method valueMethod, JsonSerializer<java.lang.Object> ser)
           
 
Method Summary
 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(java.lang.Object bean, JsonGenerator jgen, SerializerProvider prov)
          Method that can be called to ask implementation to serialize values of type this serializer handles.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonValueSerializer

public JsonValueSerializer(java.lang.reflect.Method valueMethod,
                           JsonSerializer<java.lang.Object> ser)
Parameters:
ser - Explicit serializer to use, if caller knows it (which occurs if and only if the "value method" was annotated with JsonUseSerializer), otherwise null
Method Detail

serialize

public void serialize(java.lang.Object bean,
                      JsonGenerator jgen,
                      SerializerProvider prov)
               throws java.io.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<java.lang.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:
java.io.IOException
JsonGenerationException

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 java.lang.String toString()
Overrides:
toString in class java.lang.Object