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

org.codehaus.jackson.map.ser.ReadOnlyClassToSerializerMap Maven / Gradle / Ivy

Go to download

Data Mapper package is a high-performance data binding package built on Jackson JSON processor

There is a newer version: 1.9.13
Show newest version
package org.codehaus.jackson.map.ser;

import java.util.*;

import org.codehaus.jackson.type.JavaType;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.ser.SerializerCache.*;

/**
 * Optimized lookup table for accessing two types of serializers; typed
 * and non-typed.
 */
public final class ReadOnlyClassToSerializerMap
{
    /**
     *

* NOTE: keys are {@link ClassPairKey}s (for "typed" serializers) and * {@link JavaType}s (untyped) */ final HashMap> _map; /** * We'll reuse key class to avoid unnecessary instantiations; since * this is not shared between threads, we can just reuse single * instance. */ final TypedKeyRaw _typedKeyRaw = new TypedKeyRaw(getClass()); final TypedKeyFull _typedKeyFull = new TypedKeyFull(null); final UntypedKeyRaw _untypedKeyRaw = new UntypedKeyRaw(getClass()); private ReadOnlyClassToSerializerMap(HashMap> map) { _map = map; } public ReadOnlyClassToSerializerMap instance() { return new ReadOnlyClassToSerializerMap(_map); } /** * Factory method for creating the "blueprint" lookup map. Such map * can not be used as is but just shared: to get an actual usable * instance, {@link #instance} has to be called first. */ @SuppressWarnings("unchecked") public static ReadOnlyClassToSerializerMap from(HashMap> src) { return new ReadOnlyClassToSerializerMap((HashMap>)src.clone()); } public JsonSerializer typedValueSerializer(JavaType type) { _typedKeyFull.reset(type); return _map.get(_typedKeyFull); } public JsonSerializer typedValueSerializer(Class cls) { _typedKeyRaw.reset(cls); return _map.get(_typedKeyRaw); } public JsonSerializer untypedValueSerializer(Class cls) { _untypedKeyRaw.reset(cls); return _map.get(_untypedKeyRaw); } /** * @since 1.5 */ public JsonSerializer untypedValueSerializer(JavaType type) { return _map.get(type); } }