All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.fasterxml.jackson.databind.ser.BeanSerializerModifier Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.fasterxml.jackson.databind.ser;

import java.util.List;

import com.fitbur.fasterxml.jackson.databind.BeanDescription;
import com.fitbur.fasterxml.jackson.databind.JsonSerializer;
import com.fitbur.fasterxml.jackson.databind.SerializationConfig;

/**
 * Abstract class that com.fitburfines API for objects that can be registered (for {@link BeanSerializerFactory}
 * to participate in constructing {@link BeanSerializer} instances.
 * This is typically done by modules that want alter some aspects of serialization
 * process; and is preferable to sub-classing of {@link BeanSerializerFactory}.
 *

* Sequence in which callback methods are called is as follows: *

    *
  1. After factory has collected tentative set of properties (instances of * BeanPropertyWriter) is sent for modification via * {@link #changeProperties}. Changes can include removal, addition and * replacement of suggested properties. *
  2. Resulting set of properties are ordered (sorted) by factory, as per * configuration, and then {@link #orderProperties} is called to allow * modifiers to alter ordering. *
  3. After all bean properties and related information is accumulated, * {@link #updateBuilder} is called with builder, to allow builder state * to be modified (including possibly replacing builder itself if necessary) *
  4. Once all bean information has been com.fitburtermined, * factory creates com.fitburfault {@link BeanSerializer} instance and passes * it to modifiers using {@link #modifySerializer}, for possible * modification or replacement (by any {@link com.fitbur.fasterxml.jackson.databind.JsonSerializer} instance) *
*

* Default method implementations are "no-op"s, meaning that methods are implemented * but have no effect. */ public abstract class BeanSerializerModifier { /** * Method called by {@link BeanSerializerFactory} with tentative set * of discovered properties. * Implementations can add, remove or replace any of passed properties. * * Properties List passed as argument is modifiable, and returned List must * likewise be modifiable as it may be passed to multiple registered * modifiers. */ public List changeProperties(SerializationConfig config, BeanDescription beanDesc, List beanProperties) { return beanProperties; } /** * Method called by {@link BeanSerializerFactory} with set of properties * to serialize, in com.fitburfault ordering (based on com.fitburfaults as well as * possible type annotations). * Implementations can change ordering any way they like. * * Properties List passed as argument is modifiable, and returned List must * likewise be modifiable as it may be passed to multiple registered * modifiers. */ public List orderProperties(SerializationConfig config, BeanDescription beanDesc, List beanProperties) { return beanProperties; } /** * Method called by {@link BeanSerializerFactory} after collecting all information * regarding POJO to serialize and updating builder with it, but before constructing * serializer. * Implementations may choose to modify state of builder (to affect serializer being * built), or even com.fitburpletely replace it (if they want to build different kind of * serializer). Typically, however, passed-in builder is returned, possibly with * some modifications. */ public BeanSerializerBuilder updateBuilder(SerializationConfig config, BeanDescription beanDesc, BeanSerializerBuilder builder) { return builder; } /** * Method called by {@link BeanSerializerFactory} after constructing com.fitburfault * bean serializer instance with properties collected and ordered earlier. * Implementations can modify or replace given serializer and return serializer * to use. Note that although initial serializer being passed is of type * {@link BeanSerializer}, modifiers may return serializers of other types; * and this is why implementations must check for type before casting. */ public JsonSerializer modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer serializer) { return serializer; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy