com.fasterxml.jackson.databind.jsontype.impl
Class AsExternalTypeSerializer

java.lang.Object
  extended by com.fasterxml.jackson.databind.jsontype.TypeSerializer
      extended by com.fasterxml.jackson.databind.jsontype.impl.TypeSerializerBase
          extended by com.fasterxml.jackson.databind.jsontype.impl.AsExternalTypeSerializer

public class AsExternalTypeSerializer
extends TypeSerializerBase

Type serializer that preferably embeds type information as an "external" type property; embedded in enclosing JSON object. Note that this serializer should only be used when value is being output at JSON Object context; otherwise it can not work reliably, and will have to revert operation similar to AsPropertyTypeSerializer.

Note that implementation of serialization is bit cumbersome as we must serialized external type id AFTER object; this because callback only occurs after field name has been written.


Field Summary
protected  String _typePropertyName
           
 
Fields inherited from class com.fasterxml.jackson.databind.jsontype.impl.TypeSerializerBase
_idResolver, _property
 
Constructor Summary
AsExternalTypeSerializer(TypeIdResolver idRes, BeanProperty property, String propName)
           
 
Method Summary
protected  void _writePrefix(Object value, com.fasterxml.jackson.core.JsonGenerator jgen)
           
protected  void _writePrefix(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, Class<?> type)
           
protected  void _writeSuffix(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, String typeId)
           
 AsExternalTypeSerializer forProperty(BeanProperty prop)
          Method called to create contextual version, to be used for values of given property.
 String getPropertyName()
          Name of property that contains type information, if property-based inclusion is used.
 com.fasterxml.jackson.annotation.JsonTypeInfo.As getTypeInclusion()
          Accessor for type information inclusion method that serializer uses; indicates how type information is embedded in resulting JSON.
 void writeCustomTypePrefixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, String typeId)
           
 void writeCustomTypePrefixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, String typeId)
          Method called to write initial part of type information for given value, when it will be output as JSON Object value (not as JSON Array or scalar), using specified custom type id instead of calling TypeIdResolver.
 void writeCustomTypePrefixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, String typeId)
          Method called to write initial part of type information for given value, when it will be output as scalar JSON value (not as JSON Object or Array), using specified custom type id instead of calling TypeIdResolver.
 void writeCustomTypeSuffixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, String typeId)
           
 void writeCustomTypeSuffixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, String typeId)
           
 void writeCustomTypeSuffixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, String typeId)
           
 void writeTypePrefixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator jgen)
          Method called to write initial part of type information for given value, when it will be output as JSON Array value (not as JSON Object or scalar).
 void writeTypePrefixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, Class<?> type)
          Alternative version of the prefix-for-array method, which is given actual type to use (instead of using exact type of the value); typically a super type of actual value type
 void writeTypePrefixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator jgen)
          Method called to write initial part of type information for given value, when it will be output as JSON Object value (not as JSON Array or scalar).
 void writeTypePrefixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, Class<?> type)
          Alternative version of the prefix-for-object method, which is given actual type to use (instead of using exact type of the value); typically a super type of actual value type
 void writeTypePrefixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator jgen)
          Method called to write initial part of type information for given value, when it will be output as scalar JSON value (not as JSON Object or Array).
 void writeTypePrefixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator jgen, Class<?> type)
          Alternative version of the prefix-for-scalar method, which is given actual type to use (instead of using exact type of the value); typically a super type of actual value type
 void writeTypeSuffixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator jgen)
          Method called after value has been serialized, to close any scopes opened by earlier matching call to TypeSerializer.writeTypeSuffixForScalar(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator).
 void writeTypeSuffixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator jgen)
          Method called after value has been serialized, to close any scopes opened by earlier matching call to TypeSerializer.writeTypePrefixForObject(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator).
 void writeTypeSuffixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator jgen)
          Method called after value has been serialized, to close any scopes opened by earlier matching call to TypeSerializer.writeTypePrefixForScalar(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator).
 
Methods inherited from class com.fasterxml.jackson.databind.jsontype.impl.TypeSerializerBase
getTypeIdResolver, idFromValue, idFromValueAndType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_typePropertyName

protected final String _typePropertyName
Constructor Detail

AsExternalTypeSerializer

public AsExternalTypeSerializer(TypeIdResolver idRes,
                                BeanProperty property,
                                String propName)
Method Detail

forProperty

public AsExternalTypeSerializer forProperty(BeanProperty prop)
Description copied from class: TypeSerializer
Method called to create contextual version, to be used for values of given property. This may be the type itself (as is the case for bean properties), or values contained (for Collection or Map valued properties).

Specified by:
forProperty in class TypeSerializer

getPropertyName

public String getPropertyName()
Description copied from class: TypeSerializer
Name of property that contains type information, if property-based inclusion is used.

Overrides:
getPropertyName in class TypeSerializerBase

getTypeInclusion

public com.fasterxml.jackson.annotation.JsonTypeInfo.As getTypeInclusion()
Description copied from class: TypeSerializer
Accessor for type information inclusion method that serializer uses; indicates how type information is embedded in resulting JSON.

Specified by:
getTypeInclusion in class TypeSerializerBase

writeTypePrefixForObject

public void writeTypePrefixForObject(Object value,
                                     com.fasterxml.jackson.core.JsonGenerator jgen)
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Method called to write initial part of type information for given value, when it will be output as JSON Object value (not as JSON Array or scalar). This means that context after call must be JSON Object, meaning that caller can then proceed to output field entries.

Specified by:
writeTypePrefixForObject in class TypeSerializer
Parameters:
value - Value that will be serialized, for which type information is to be written
jgen - Generator to use for writing type information
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeTypePrefixForObject

public void writeTypePrefixForObject(Object value,
                                     com.fasterxml.jackson.core.JsonGenerator jgen,
                                     Class<?> type)
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Alternative version of the prefix-for-object method, which is given actual type to use (instead of using exact type of the value); typically a super type of actual value type

Overrides:
writeTypePrefixForObject in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeTypePrefixForArray

public void writeTypePrefixForArray(Object value,
                                    com.fasterxml.jackson.core.JsonGenerator jgen)
                             throws IOException,
                                    com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Method called to write initial part of type information for given value, when it will be output as JSON Array value (not as JSON Object or scalar). This means that context after call must be JSON Array, that is, there must be an open START_ARRAY to write contents in.

Specified by:
writeTypePrefixForArray in class TypeSerializer
Parameters:
value - Value that will be serialized, for which type information is to be written
jgen - Generator to use for writing type information
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeTypePrefixForArray

public void writeTypePrefixForArray(Object value,
                                    com.fasterxml.jackson.core.JsonGenerator jgen,
                                    Class<?> type)
                             throws IOException,
                                    com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Alternative version of the prefix-for-array method, which is given actual type to use (instead of using exact type of the value); typically a super type of actual value type

Overrides:
writeTypePrefixForArray in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeTypePrefixForScalar

public void writeTypePrefixForScalar(Object value,
                                     com.fasterxml.jackson.core.JsonGenerator jgen)
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Method called to write initial part of type information for given value, when it will be output as scalar JSON value (not as JSON Object or Array). This means that the context after call can not be that of JSON Object; it may be Array or root context.

Specified by:
writeTypePrefixForScalar in class TypeSerializer
Parameters:
value - Value that will be serialized, for which type information is to be written
jgen - Generator to use for writing type information
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeTypePrefixForScalar

public void writeTypePrefixForScalar(Object value,
                                     com.fasterxml.jackson.core.JsonGenerator jgen,
                                     Class<?> type)
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Alternative version of the prefix-for-scalar method, which is given actual type to use (instead of using exact type of the value); typically a super type of actual value type

Overrides:
writeTypePrefixForScalar in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeTypeSuffixForObject

public void writeTypeSuffixForObject(Object value,
                                     com.fasterxml.jackson.core.JsonGenerator jgen)
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Method called after value has been serialized, to close any scopes opened by earlier matching call to TypeSerializer.writeTypePrefixForObject(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator). It needs to write closing END_OBJECT marker, and any other decoration that needs to be matched.

Specified by:
writeTypeSuffixForObject in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeTypeSuffixForArray

public void writeTypeSuffixForArray(Object value,
                                    com.fasterxml.jackson.core.JsonGenerator jgen)
                             throws IOException,
                                    com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Method called after value has been serialized, to close any scopes opened by earlier matching call to TypeSerializer.writeTypeSuffixForScalar(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator). It needs to write closing END_ARRAY marker, and any other decoration that needs to be matched.

Specified by:
writeTypeSuffixForArray in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeTypeSuffixForScalar

public void writeTypeSuffixForScalar(Object value,
                                     com.fasterxml.jackson.core.JsonGenerator jgen)
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Method called after value has been serialized, to close any scopes opened by earlier matching call to TypeSerializer.writeTypePrefixForScalar(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator). Actual action to take may depend on various factors, but has to match with action TypeSerializer.writeTypePrefixForScalar(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator) did (close array or object; or do nothing).

Specified by:
writeTypeSuffixForScalar in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeCustomTypePrefixForScalar

public void writeCustomTypePrefixForScalar(Object value,
                                           com.fasterxml.jackson.core.JsonGenerator jgen,
                                           String typeId)
                                    throws IOException,
                                           com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Method called to write initial part of type information for given value, when it will be output as scalar JSON value (not as JSON Object or Array), using specified custom type id instead of calling TypeIdResolver. This means that the context after call can not be that of JSON Object; it may be Array or root context.

Specified by:
writeCustomTypePrefixForScalar in class TypeSerializer
Parameters:
value - Value that will be serialized, for which type information is to be written
jgen - Generator to use for writing type information
typeId - Exact type id to use
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeCustomTypePrefixForObject

public void writeCustomTypePrefixForObject(Object value,
                                           com.fasterxml.jackson.core.JsonGenerator jgen,
                                           String typeId)
                                    throws IOException,
                                           com.fasterxml.jackson.core.JsonProcessingException
Description copied from class: TypeSerializer
Method called to write initial part of type information for given value, when it will be output as JSON Object value (not as JSON Array or scalar), using specified custom type id instead of calling TypeIdResolver. This means that context after call must be JSON Object, meaning that caller can then proceed to output field entries.

Specified by:
writeCustomTypePrefixForObject in class TypeSerializer
Parameters:
value - Value that will be serialized, for which type information is to be written
jgen - Generator to use for writing type information
typeId - Exact type id to use
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeCustomTypePrefixForArray

public void writeCustomTypePrefixForArray(Object value,
                                          com.fasterxml.jackson.core.JsonGenerator jgen,
                                          String typeId)
                                   throws IOException,
                                          com.fasterxml.jackson.core.JsonProcessingException
Specified by:
writeCustomTypePrefixForArray in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeCustomTypeSuffixForScalar

public void writeCustomTypeSuffixForScalar(Object value,
                                           com.fasterxml.jackson.core.JsonGenerator jgen,
                                           String typeId)
                                    throws IOException,
                                           com.fasterxml.jackson.core.JsonProcessingException
Specified by:
writeCustomTypeSuffixForScalar in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeCustomTypeSuffixForObject

public void writeCustomTypeSuffixForObject(Object value,
                                           com.fasterxml.jackson.core.JsonGenerator jgen,
                                           String typeId)
                                    throws IOException,
                                           com.fasterxml.jackson.core.JsonProcessingException
Specified by:
writeCustomTypeSuffixForObject in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

writeCustomTypeSuffixForArray

public void writeCustomTypeSuffixForArray(Object value,
                                          com.fasterxml.jackson.core.JsonGenerator jgen,
                                          String typeId)
                                   throws IOException,
                                          com.fasterxml.jackson.core.JsonProcessingException
Specified by:
writeCustomTypeSuffixForArray in class TypeSerializer
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

_writePrefix

protected final void _writePrefix(Object value,
                                  com.fasterxml.jackson.core.JsonGenerator jgen)
                           throws IOException,
                                  com.fasterxml.jackson.core.JsonProcessingException
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

_writePrefix

protected final void _writePrefix(Object value,
                                  com.fasterxml.jackson.core.JsonGenerator jgen,
                                  Class<?> type)
                           throws IOException,
                                  com.fasterxml.jackson.core.JsonProcessingException
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException

_writeSuffix

protected final void _writeSuffix(Object value,
                                  com.fasterxml.jackson.core.JsonGenerator jgen,
                                  String typeId)
                           throws IOException,
                                  com.fasterxml.jackson.core.JsonProcessingException
Throws:
IOException
com.fasterxml.jackson.core.JsonProcessingException


Copyright © 2012 fasterxml.com. All Rights Reserved.