/** * Interface that is to replace {@link JsonSerializable} to * allow for dynamic type information embedding. * * @since 1.5 * @author tatu */ @SuppressWarnings("deprecation") publicinterfaceJsonSerializableWithType extendsJsonSerializable { publicvoidserializeWithType(JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonProcessingException; }
/** * 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. *<p> * Default implementation will ignore serialization of type information, * and just calls {@link #serialize}: serializers that can embed * type information should override this to implement actual handling. * Most common such handling is done by something like: *<pre> * // 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); *</pre> */ publicvoidserializeWithType(T value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonProcessingException { serialize(value, jgen, provider); } }
/** * Annotation used for configuring serialization aspects, by attaching * to "getter" methods or fields, or to value classes. * When annotating value classes, configuration is used for instances * of the value class but can be overridden by more specific annotations * (ones that attach to methods or fields). *<p> * An example annotation would be: *<pre> * @JsonSerialize(using=MySerializer.class, * as=MySubClass.class, * include=JsonSerialize.Inclusion.NON_NULL, * typing=JsonSerialize.Typing.STATIC * ) *</pre> * (which would be redundant, since some properties block others: * specifically, 'using' has precedence over 'as', which has precedence * over 'typing' setting) *<p> * NOTE: since version 1.2, annotation has also been applicable * to (constructor) parameters * * @since 1.1 */ @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public@interface JsonSerialize { // // // Annotations for explicitly specifying deserializer
/** * Serializer class to use for * serializing associated value. Depending on what is annotated, * value is either an instance of annotated class (used globablly * anywhere where class serializer is needed); or only used for * serializing property access via a getter method. */ public Class<? extends JsonSerializer<?>> using() default JsonSerializer.None.class;
// SimpleModule SerializeModule = new SimpleModule("SerializeModule", new Version(1, 0, 0, null)); // SerializeModule.addSerializer(new CustomizeJsonSerializerBaser(TypeB.class)); // assuming serializer declares correct class to bind to // objectMapper.registerModule(SerializeModule);