Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.codehaus.jackson.map.ser;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import org.codehaus.jackson.map.*;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.ext.OptionalHandlerFactory;
import org.codehaus.jackson.map.introspect.Annotated;
import org.codehaus.jackson.map.introspect.AnnotatedClass;
import org.codehaus.jackson.map.introspect.AnnotatedMethod;
import org.codehaus.jackson.map.introspect.BasicBeanDescription;
import org.codehaus.jackson.map.jsontype.NamedType;
import org.codehaus.jackson.map.jsontype.TypeResolverBuilder;
import org.codehaus.jackson.map.type.TypeFactory;
import org.codehaus.jackson.map.util.ClassUtil;
import org.codehaus.jackson.map.util.EnumValues;
import org.codehaus.jackson.type.JavaType;
import org.codehaus.jackson.util.TokenBuffer;
/**
* Factory class that can provide serializers for standard JDK classes,
* as well as custom classes that extend standard classes or implement
* one of "well-known" interfaces (such as {@link java.util.Collection}).
*
* Since all the serializers are eagerly instantiated, and there is
* no additional introspection or customizability of these types,
* this factory is stateless. This means that other delegating
* factories (or {@link SerializerProvider}s) can just use the
* shared singleton instance via static {@link #instance} field.
*/
public class BasicSerializerFactory
extends SerializerFactory
{
/*
/**********************************************************
/* Configuration, lookup tables/maps
/**********************************************************
*/
/**
* Since these are all JDK classes, we shouldn't have to worry
* about ClassLoader used to load them. Rather, we can just
* use the class name, and keep things simple and efficient.
*/
protected final static HashMap> _concrete =
new HashMap>();
/**
* Actually it may not make much sense to eagerly instantiate all
* kinds of serializers: so this Map actually contains class references,
* not instances
*
* @since 1.6
*/
protected final static HashMap>> _concreteLazy =
new HashMap>>();
static {
/* String and string-like types (note: date types explicitly
* not included -- can use either textual or numeric serialization)
*/
_concrete.put(String.class.getName(), new StdSerializers.StringSerializer());
final ToStringSerializer sls = ToStringSerializer.instance;
_concrete.put(StringBuffer.class.getName(), sls);
_concrete.put(StringBuilder.class.getName(), sls);
_concrete.put(Character.class.getName(), sls);
_concrete.put(Character.TYPE.getName(), sls);
// Primitives/wrappers for primitives (primitives needed for Beans)
_concrete.put(Boolean.TYPE.getName(), new StdSerializers.BooleanSerializer(true));
_concrete.put(Boolean.class.getName(), new StdSerializers.BooleanSerializer(false));
final JsonSerializer> intS = new StdSerializers.IntegerSerializer();
_concrete.put(Integer.class.getName(), intS);
_concrete.put(Integer.TYPE.getName(), intS);
_concrete.put(Long.class.getName(), StdSerializers.LongSerializer.instance);
_concrete.put(Long.TYPE.getName(), StdSerializers.LongSerializer.instance);
_concrete.put(Byte.class.getName(), StdSerializers.IntLikeSerializer.instance);
_concrete.put(Byte.TYPE.getName(), StdSerializers.IntLikeSerializer.instance);
_concrete.put(Short.class.getName(), StdSerializers.IntLikeSerializer.instance);
_concrete.put(Short.TYPE.getName(), StdSerializers.IntLikeSerializer.instance);
// Numbers, limited length floating point
_concrete.put(Float.class.getName(), StdSerializers.FloatSerializer.instance);
_concrete.put(Float.TYPE.getName(), StdSerializers.FloatSerializer.instance);
_concrete.put(Double.class.getName(), StdSerializers.DoubleSerializer.instance);
_concrete.put(Double.TYPE.getName(), StdSerializers.DoubleSerializer.instance);
// Other numbers, more complicated
final JsonSerializer> ns = new StdSerializers.NumberSerializer();
_concrete.put(BigInteger.class.getName(), ns);
_concrete.put(BigDecimal.class.getName(), ns);
/* Other discrete non-container types:
* first, Date/Time zoo:
*/
_concrete.put(Calendar.class.getName(), StdSerializers.CalendarSerializer.instance);
_concrete.put(java.util.Date.class.getName(), StdSerializers.UtilDateSerializer.instance);
_concrete.put(java.sql.Date.class.getName(), new StdSerializers.SqlDateSerializer());
_concrete.put(java.sql.Time.class.getName(), new StdSerializers.SqlTimeSerializer());
// note: timestamps are very similar to java.util.Date, thus serialized as such
_concrete.put(java.sql.Timestamp.class.getName(), StdSerializers.UtilDateSerializer.instance);
// Arrays of various types (including common object types)
_concrete.put(boolean[].class.getName(), new ArraySerializers.BooleanArraySerializer());
_concrete.put(byte[].class.getName(), new ArraySerializers.ByteArraySerializer());
_concrete.put(char[].class.getName(), new ArraySerializers.CharArraySerializer());
_concrete.put(short[].class.getName(), new ArraySerializers.ShortArraySerializer());
_concrete.put(int[].class.getName(), new ArraySerializers.IntArraySerializer());
_concrete.put(long[].class.getName(), new ArraySerializers.LongArraySerializer());
_concrete.put(float[].class.getName(), new ArraySerializers.FloatArraySerializer());
_concrete.put(double[].class.getName(), new ArraySerializers.DoubleArraySerializer());
_concrete.put(Object[].class.getName(), ArraySerializers.ObjectArraySerializer.instance);
_concrete.put(String[].class.getName(), new ArraySerializers.StringArraySerializer());
// And then Java Collection classes
final ContainerSerializers.IndexedListSerializer indListS = ContainerSerializers.IndexedListSerializer.instance;
final ContainerSerializers.CollectionSerializer collectionS = ContainerSerializers.CollectionSerializer.instance;
_concrete.put(ArrayList.class.getName(), indListS);
_concrete.put(Vector.class.getName(), indListS);
_concrete.put(LinkedList.class.getName(), collectionS);
// (java.util.concurrent has others, but let's allow those to be
// found via slower introspection; too many to enumerate here)
final MapSerializer mapS = MapSerializer.instance;
_concrete.put(HashMap.class.getName(), mapS);
_concrete.put(Hashtable.class.getName(), mapS);
_concrete.put(LinkedHashMap.class.getName(), mapS);
_concrete.put(TreeMap.class.getName(), mapS);
_concrete.put(Properties.class.getName(), mapS);
_concrete.put(HashSet.class.getName(), collectionS);
_concrete.put(LinkedHashSet.class.getName(), collectionS);
_concrete.put(TreeSet.class.getName(), collectionS);
// And then other standard non-structured JDK types
for (Map.Entry,Object> en : new JdkSerializers().provide()) {
Object value = en.getValue();
if (value instanceof JsonSerializer>) {
_concrete.put(en.getKey().getName(), (JsonSerializer>) value);
} else if (value instanceof Class>) {
@SuppressWarnings("unchecked")
Class extends JsonSerializer>> cls = (Class extends JsonSerializer>>) value;
_concreteLazy.put(en.getKey().getName(), cls);
} else { // should never happen, but:
throw new IllegalStateException("Internal error: unrecognized value of type "+en.getClass().getName());
}
}
// Jackson-specific type(s)
// (Q: can this ever be sub-classed?)
_concreteLazy.put(TokenBuffer.class.getName(), StdSerializers.TokenBufferSerializer.class);
}
protected OptionalHandlerFactory optionalHandlers = OptionalHandlerFactory.instance;
/*
/**********************************************************
/* Life cycle
/**********************************************************
*/
/**
* Stateless global singleton instance that should be used
* for factories that want to use delegation to access
* standard serializers.
*/
public final static BasicSerializerFactory instance = new BasicSerializerFactory();
/**
* We will provide default constructor to allow sub-classing,
* but make it protected so that no non-singleton instances of
* the class will be instantiated.
*/
protected BasicSerializerFactory() { }
/*
/**********************************************************
/* SerializerFactory impl
/**********************************************************
*/
/**
* Main serializer constructor method. The base implementation within
* this class first calls a fast lookup method that can find serializers
* for well-known JDK classes; and if that fails, a slower one that
* tries to check out which interfaces given Class implements.
* Sub-classes can (and do) change this behavior to alter behavior.
*/
@Override
@SuppressWarnings("unchecked")
public JsonSerializer createSerializer(Class type, SerializationConfig config)
{
return (JsonSerializer) createSerializer(TypeFactory.type(type), config);
}
@Override
@SuppressWarnings("unchecked")
public JsonSerializer