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

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

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

import com.fitbur.fasterxml.jackson.databind.*;
import com.fitbur.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fitbur.fasterxml.jackson.databind.type.*;

/**
 * Interface that com.fitburfines API for simple extensions that can provide additional serializers
 * for various types. Access is by a single callback method; instance is to either return
 * a configured {@link JsonSerializer} for specified type, or null to indicate that it
 * does not support handling of the type. In latter case, further calls can be made
 * for other providers; in former case returned serializer is used for handling of
 * instances of specified type.
 */
public interface Serializers
{
    /**
     * Method called by serialization framework first time a serializer is needed for
     * specified type, which is not of a container type (for which other methods are
     * called).
     * 
     * @param type Fully resolved type of instances to serialize
     * @param config Serialization configuration in use
     * @param beanDesc Additional information about type
     *    
     * @return Configured serializer to use for the type; or null if implementation
     *    does not recognize or support type
     */
    public JsonSerializer findSerializer(SerializationConfig config,
            JavaType type, BeanDescription beanDesc);

    /**
     * Method called by serialization framework first time a serializer is needed for
     * specified array type.
     * Implementation should return a serializer instance if it supports
     * specified type; or null if it does not.
     */
    public JsonSerializer findArraySerializer(SerializationConfig config,
            ArrayType type, BeanDescription beanDesc,
            TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer);

    /**
     * Method called by serialization framework first time a serializer is needed for
     * specified {@link java.util.Collection} type.
     * Implementation should return a serializer instance if it supports
     * specified type; or null if it does not.
     */
    public JsonSerializer findCollectionSerializer(SerializationConfig config,
            CollectionType type, BeanDescription beanDesc,
            TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer);

    /**
     * Method called by serialization framework first time a serializer is needed for
     * specified "Collection-like" type (type that acts like {@link java.util.Collection},
     * but does not implement it).
     * Implementation should return a serializer instance if it supports
     * specified type; or null if it does not.
     */
    public JsonSerializer findCollectionLikeSerializer(SerializationConfig config,
            CollectionLikeType type, BeanDescription beanDesc,
            TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer);
    
    /**
     * Method called by serialization framework first time a serializer is needed for
     * specified {@link java.util.Map} type.
     * Implementation should return a serializer instance if it supports
     * specified type; or null if it does not.
     */
    public JsonSerializer findMapSerializer(SerializationConfig config,
            MapType type, BeanDescription beanDesc,
            JsonSerializer keySerializer,
            TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer);

    /**
     * Method called by serialization framework first time a serializer is needed for
     * specified "Map-like" type (type that acts like {@link java.util.Map},
     * but does not implement it).
     * Implementation should return a serializer instance if it supports
     * specified type; or null if it does not.
     */
    public JsonSerializer findMapLikeSerializer(SerializationConfig config,
            MapLikeType type, BeanDescription beanDesc,
            JsonSerializer keySerializer,
            TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer);

    /**
     * Basic {@link Serializers} implementation that implements all methods but provides
     * no serializers. Its main purpose is to serve as a base class so that
     * sub-classes only need to override methods they need.
     */
    public static class Base implements Serializers
    {
//      @Override
        public JsonSerializer findSerializer(SerializationConfig config,
                JavaType type, BeanDescription beanDesc)
        {
            return null;
        }
        
//      @Override
        public JsonSerializer findArraySerializer(SerializationConfig config,
                ArrayType type, BeanDescription beanDesc,
                TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer)
        {
            return null;
        }

//      @Override
        public JsonSerializer findCollectionSerializer(SerializationConfig config,
                CollectionType type, BeanDescription beanDesc,
                TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer)
        {
            return null;
        }

//      @Override
        public JsonSerializer findCollectionLikeSerializer(SerializationConfig config,
                CollectionLikeType type, BeanDescription beanDesc,
                TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer)
        {
            return null;
        }
            
//      @Override
        public JsonSerializer findMapSerializer(SerializationConfig config,
                MapType type, BeanDescription beanDesc,
                JsonSerializer keySerializer,
                TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer)
        {
            return null;
        }

//      @Override
        public JsonSerializer findMapLikeSerializer(SerializationConfig config,
                MapLikeType type, BeanDescription beanDesc,
                JsonSerializer keySerializer,
                TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer)
        {
            return null;
        }
    }
}