public interface JsonSerializable
JsonGenerator
(and SerializerProvider
if necessary).
Note that implementing this interface binds implementing object closely to Jackson API, and that it is often not necessary to do so -- if class is a bean, it can be serialized without implementing this interface.
NOTE: Jackson 2.0 added another method (from former "JsonSerializableWithType"), which is required for proper handling of case where additional type information is needed.
Modifier and Type | Method and Description |
---|---|
void |
serialize(JsonGenerator jgen,
SerializerProvider provider)
Serialization method called when no additional type information is
to be included in serialization.
|
void |
serializeWithType(JsonGenerator jgen,
SerializerProvider provider,
TypeSerializer typeSer)
Serialization method called when additional type information is
expected to be included in serialization, for deserialization to use.
|
void serialize(JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException
IOException
JsonProcessingException
void serializeWithType(JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonProcessingException
Usually implementation consists of a call to one of methods
in TypeSerializer
(such as TypeSerializer.writeTypePrefixForObject(Object, JsonGenerator)
)
followed by serialization of contents,
followed by another call to TypeSerializer
(such as TypeSerializer.writeTypeSuffixForObject(Object, JsonGenerator)
).
Exact methods to call in TypeSerializer
depend on shape of JSON Object used
(Array, Object or scalar like String/Number/Boolean).
Note that some types (most notably, "natural" types: String, Integer, Double and Boolean) never include type information.
IOException
JsonProcessingException
Copyright © 2012-2013 FasterXML. All Rights Reserved.