Package org.codehaus.jackson.map.ser.std
Class SerializerBase<T>
- java.lang.Object
-
- org.codehaus.jackson.map.JsonSerializer<T>
-
- org.codehaus.jackson.map.ser.std.SerializerBase<T>
-
- All Implemented Interfaces:
SchemaAware
- Direct Known Subclasses:
BeanSerializerBase
,ContainerSerializerBase
,CoreXMLSerializers.XMLGregorianCalendarSerializer
,DataHandlerJsonSerializer
,DomElementJsonSerializer
,DOMSerializer
,FailingSerializer
,JodaSerializers.JodaSerializer
,JsonValueSerializer
,NullSerializer
,RawSerializer
,ScalarSerializerBase
,ScalarSerializerBase
,SerializableWithTypeSerializer
,SerializerBase
,StaticListSerializerBase
,StdArraySerializers.ByteArraySerializer
,StdArraySerializers.CharArraySerializer
,StdJdkSerializers.AtomicReferenceSerializer
,StdKeySerializer
,StdKeySerializers.CalendarKeySerializer
,StdKeySerializers.DateKeySerializer
,StdKeySerializers.StringKeySerializer
,TokenBufferSerializer
,ToStringSerializer
,UnknownSerializer
,XmlAdapterJsonSerializer
public abstract class SerializerBase<T> extends JsonSerializer<T> implements SchemaAware
Base class used by all standard serializers. Provides some convenience methods for implementingSchemaAware
- Since:
- 1.9 (renamed from 'org.codehaus.jackson.map.ser.SerializerBase')
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.codehaus.jackson.map.JsonSerializer
JsonSerializer.None
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<T>
_handledType
-
Constructor Summary
Constructors Modifier Constructor Description protected
SerializerBase(java.lang.Class<?> t, boolean dummy)
Alternate constructor that is (alas!) needed to work around kinks of generic type handlingprotected
SerializerBase(java.lang.Class<T> t)
protected
SerializerBase(JavaType type)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected ObjectNode
createObjectNode()
protected ObjectNode
createSchemaNode(java.lang.String type)
protected ObjectNode
createSchemaNode(java.lang.String type, boolean isOptional)
JsonNode
getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint)
Note: since Jackson 1.9, default implementation claims type is "string"java.lang.Class<T>
handledType()
Method for accessing type of Objects this serializer can handle.protected boolean
isDefaultSerializer(JsonSerializer<?> serializer)
Method that can be called to determine if given serializer is the default serializer Jackson uses; as opposed to a custom serializer installed by a module or calling application.abstract void
serialize(T value, JsonGenerator jgen, SerializerProvider provider)
Method that can be called to ask implementation to serialize values of type this serializer handles.void
wrapAndThrow(java.lang.Throwable t, java.lang.Object bean, int index)
Deprecated.Use version that takesSerializerProvider
instead.void
wrapAndThrow(java.lang.Throwable t, java.lang.Object bean, java.lang.String fieldName)
Deprecated.Use version that takesSerializerProvider
instead.void
wrapAndThrow(SerializerProvider provider, java.lang.Throwable t, java.lang.Object bean, int index)
void
wrapAndThrow(SerializerProvider provider, java.lang.Throwable t, java.lang.Object bean, java.lang.String fieldName)
Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype ofIOException
, or an unchecked exception.-
Methods inherited from class org.codehaus.jackson.map.JsonSerializer
isUnwrappingSerializer, serializeWithType, unwrappingSerializer
-
-
-
-
Field Detail
-
_handledType
protected final java.lang.Class<T> _handledType
-
-
Constructor Detail
-
SerializerBase
protected SerializerBase(java.lang.Class<T> t)
-
SerializerBase
protected SerializerBase(JavaType type)
- Since:
- 1.7
-
SerializerBase
protected SerializerBase(java.lang.Class<?> t, boolean dummy)
Alternate constructor that is (alas!) needed to work around kinks of generic type handling
-
-
Method Detail
-
handledType
public final java.lang.Class<T> handledType()
Description copied from class:JsonSerializer
Method for accessing type of Objects this serializer can handle. Note that this information is not guaranteed to be exact -- it may be a more generic (super-type) -- but it should not be incorrect (return a non-related type).Default implementation will return null, which essentially means same as returning
Object.class
would; that is, that nothing is known about handled type.- Overrides:
handledType
in classJsonSerializer<T>
-
serialize
public abstract void serialize(T value, JsonGenerator jgen, SerializerProvider provider) 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 classJsonSerializer<T>
- Parameters:
value
- Value to serialize; can not be null.jgen
- Generator used to output resulting Json contentprovider
- Provider that can be used to get serializers for serializing Objects value contains, if any.- Throws:
java.io.IOException
JsonGenerationException
-
getSchema
public JsonNode getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint) throws JsonMappingException
Note: since Jackson 1.9, default implementation claims type is "string"- Specified by:
getSchema
in interfaceSchemaAware
- Parameters:
provider
- The serializer provider.typeHint
- A hint about the type.- Returns:
- Json-schema for this serializer.
- Throws:
JsonMappingException
-
createObjectNode
protected ObjectNode createObjectNode()
-
createSchemaNode
protected ObjectNode createSchemaNode(java.lang.String type)
-
createSchemaNode
protected ObjectNode createSchemaNode(java.lang.String type, boolean isOptional)
-
isDefaultSerializer
protected boolean isDefaultSerializer(JsonSerializer<?> serializer)
Method that can be called to determine if given serializer is the default serializer Jackson uses; as opposed to a custom serializer installed by a module or calling application. Determination is done usingJacksonStdImpl
annotation on serializer class.- Since:
- 1.7
-
wrapAndThrow
public void wrapAndThrow(SerializerProvider provider, java.lang.Throwable t, java.lang.Object bean, java.lang.String fieldName) throws java.io.IOException
Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype ofIOException
, or an unchecked exception.Rules for wrapping and unwrapping are bit complicated; essentially:
- Errors are to be passed as is (if uncovered via unwrapping)
- "Plain" IOExceptions (ones that are not of type
JsonMappingException
are to be passed as is
- Throws:
java.io.IOException
-
wrapAndThrow
public void wrapAndThrow(SerializerProvider provider, java.lang.Throwable t, java.lang.Object bean, int index) throws java.io.IOException
- Throws:
java.io.IOException
-
wrapAndThrow
@Deprecated public void wrapAndThrow(java.lang.Throwable t, java.lang.Object bean, java.lang.String fieldName) throws java.io.IOException
Deprecated.Use version that takesSerializerProvider
instead.- Throws:
java.io.IOException
-
wrapAndThrow
@Deprecated public void wrapAndThrow(java.lang.Throwable t, java.lang.Object bean, int index) throws java.io.IOException
Deprecated.Use version that takesSerializerProvider
instead.- Throws:
java.io.IOException
-
-