|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.fasterxml.jackson.databind.JsonSerializer<T> com.fasterxml.jackson.databind.ser.std.StdSerializer<Object> com.fasterxml.jackson.databind.ser.std.BeanSerializerBase
public abstract class BeanSerializerBase
Base class both for the standard bean serializer, and couple of variants that only differ in small details. Can be used for custom bean serializers as well, although that is not the primary design goal.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer |
---|
JsonSerializer.None |
Field Summary | |
---|---|
protected AnyGetterWriter |
_anyGetterWriter
Handler for JsonAnyGetter
annotated properties |
protected BeanPropertyWriter[] |
_filteredProps
Optional filters used to suppress output of properties that are only to be included in certain views |
protected ObjectIdWriter |
_objectIdWriter
If this POJO can be alternatively serialized using just an object id to denote a reference to previously serialized object, this Object will handle details. |
protected Object |
_propertyFilterId
Id of the bean property filter to use, if any; null if none. |
protected BeanPropertyWriter[] |
_props
Writers used for outputting actual property values |
protected AnnotatedMember |
_typeId
If using custom type ids (usually via getter, or field), this is the reference to that member. |
protected static BeanPropertyWriter[] |
NO_PROPS
|
Fields inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer |
---|
_handledType |
Constructor Summary | |
---|---|
protected |
BeanSerializerBase(BeanSerializerBase src)
Copy-constructor that is useful for sub-classes that just want to copy all super-class properties without modifications. |
|
BeanSerializerBase(BeanSerializerBase src,
BeanPropertyWriter[] properties,
BeanPropertyWriter[] filteredProperties)
|
protected |
BeanSerializerBase(BeanSerializerBase src,
NameTransformer unwrapper)
Copy-constructor that will also rename properties with given prefix (if it's non-empty) |
protected |
BeanSerializerBase(BeanSerializerBase src,
ObjectIdWriter objectIdWriter)
|
protected |
BeanSerializerBase(BeanSerializerBase src,
String[] toIgnore)
|
protected |
BeanSerializerBase(JavaType type,
BeanSerializerBuilder builder,
BeanPropertyWriter[] properties,
BeanPropertyWriter[] filteredProperties)
Constructor used by BeanSerializerBuilder to create an
instance |
Method Summary | |
---|---|
JsonSerializer<?> |
createContextual(SerializerProvider provider,
BeanProperty property)
Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property. |
protected BeanPropertyFilter |
findFilter(SerializerProvider provider)
Helper method used to locate filter that is needed, based on filter id this serializer was constructed with. |
JsonNode |
getSchema(SerializerProvider provider,
Type typeHint)
Default implementation simply claims type is "string"; usually overriden by custom serializers. |
void |
resolve(SerializerProvider provider)
We need to implement ResolvableSerializer to be able to
properly handle cyclic type references. |
abstract void |
serialize(Object bean,
com.fasterxml.jackson.core.JsonGenerator jgen,
SerializerProvider provider)
Method that can be called to ask implementation to serialize values of type this serializer handles. |
protected void |
serializeFields(Object bean,
com.fasterxml.jackson.core.JsonGenerator jgen,
SerializerProvider provider)
|
protected void |
serializeFieldsFiltered(Object bean,
com.fasterxml.jackson.core.JsonGenerator jgen,
SerializerProvider provider)
Alternative serialization method that gets called when there is a BeanPropertyFilter that needs to be called to determine
which properties are to be serialized (and possibly how) |
void |
serializeWithType(Object bean,
com.fasterxml.jackson.core.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. |
boolean |
usesObjectId()
Method that can be called to see whether this serializer instance will use Object Id to handle cyclic references. |
protected abstract BeanSerializerBase |
withIgnorals(String[] toIgnore)
Fluent factory used for creating a new instance with additional set of properties to ignore (from properties this instance otherwise has) |
protected abstract BeanSerializerBase |
withObjectIdWriter(ObjectIdWriter objectIdWriter)
Fluent factory used for creating a new instance with different ObjectIdWriter . |
Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer |
---|
createObjectNode, createSchemaNode, createSchemaNode, handledType, isDefaultSerializer, wrapAndThrow, wrapAndThrow |
Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer |
---|
isEmpty, isUnwrappingSerializer, unwrappingSerializer |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final BeanPropertyWriter[] NO_PROPS
protected final BeanPropertyWriter[] _props
protected final BeanPropertyWriter[] _filteredProps
protected final AnyGetterWriter _anyGetterWriter
JsonAnyGetter
annotated properties
protected final Object _propertyFilterId
protected final AnnotatedMember _typeId
protected final ObjectIdWriter _objectIdWriter
Note: not final since we need to get contextual instance during resolution.
Constructor Detail |
---|
protected BeanSerializerBase(JavaType type, BeanSerializerBuilder builder, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)
BeanSerializerBuilder
to create an
instance
type
- Nominal type of values handled by this serializerbuilder
- Builder for accessing other collected informationpublic BeanSerializerBase(BeanSerializerBase src, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)
protected BeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter)
protected BeanSerializerBase(BeanSerializerBase src, String[] toIgnore)
protected BeanSerializerBase(BeanSerializerBase src)
protected BeanSerializerBase(BeanSerializerBase src, NameTransformer unwrapper)
Method Detail |
---|
protected abstract BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter)
ObjectIdWriter
.
protected abstract BeanSerializerBase withIgnorals(String[] toIgnore)
public void resolve(SerializerProvider provider) throws JsonMappingException
ResolvableSerializer
to be able to
properly handle cyclic type references.
resolve
in interface ResolvableSerializer
provider
- Provider that has constructed serializer this method
is called on.
JsonMappingException
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) throws JsonMappingException
ContextualSerializer
createContextual
in interface ContextualSerializer
provider
- Serializer provider to use for accessing config, other serializersproperty
- Method or field that represents the property
(and is used to access value to serialize).
Should be available; but there may be cases where caller can not provide it and
null is passed instead (in which case impls usually pass 'this' serializer as is)
JsonMappingException
public boolean usesObjectId()
JsonSerializer
usesObjectId
in class JsonSerializer<Object>
public abstract void serialize(Object bean, com.fasterxml.jackson.core.JsonGenerator jgen, SerializerProvider provider) throws IOException, com.fasterxml.jackson.core.JsonGenerationException
JsonSerializer
serialize
in class StdSerializer<Object>
bean
- 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.
IOException
com.fasterxml.jackson.core.JsonGenerationException
public void serializeWithType(Object bean, com.fasterxml.jackson.core.JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, com.fasterxml.jackson.core.JsonGenerationException
JsonSerializer
Default implementation will throw UnsupportedOperationException
to indicate that proper type handling needs to be implemented.
For simple datatypes written as a single scalar value (JSON String, Number, Boolean), implementation would look 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);and implementations for type serialized as JSON Arrays or Objects would differ slightly, as
START-ARRAY>/END-ARRAY
and
START-OBJECT>/END-OBJECT
pairs
need to be properly handled with respect to serializing of contents.
- Overrides:
serializeWithType
in class JsonSerializer<Object>
- Parameters:
bean
- 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.typeSer
- Type serializer to use for including type information
- Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException
protected void serializeFields(Object bean, com.fasterxml.jackson.core.JsonGenerator jgen, SerializerProvider provider) throws IOException, com.fasterxml.jackson.core.JsonGenerationException
IOException
com.fasterxml.jackson.core.JsonGenerationException
protected void serializeFieldsFiltered(Object bean, com.fasterxml.jackson.core.JsonGenerator jgen, SerializerProvider provider) throws IOException, com.fasterxml.jackson.core.JsonGenerationException
BeanPropertyFilter
that needs to be called to determine
which properties are to be serialized (and possibly how)
IOException
com.fasterxml.jackson.core.JsonGenerationException
protected BeanPropertyFilter findFilter(SerializerProvider provider) throws JsonMappingException
JsonMappingException
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException
StdSerializer
getSchema
in interface SchemaAware
getSchema
in class StdSerializer<Object>
provider
- The serializer provider.typeHint
- A hint about the type.
JsonMappingException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |