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.net.InetAddress;
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.*;
import org.codehaus.jackson.map.jsontype.NamedType;
import org.codehaus.jackson.map.jsontype.TypeResolverBuilder;
import org.codehaus.jackson.map.ser.impl.IndexedStringListSerializer;
import org.codehaus.jackson.map.ser.impl.InetAddressSerializer;
import org.codehaus.jackson.map.ser.impl.ObjectArraySerializer;
import org.codehaus.jackson.map.ser.impl.StringCollectionSerializer;
import org.codehaus.jackson.map.ser.impl.TimeZoneSerializer;
import org.codehaus.jackson.map.type.*;
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 essentially stateless.
*/
public abstract 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);
// 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 final static HashMap> _arraySerializers =
new HashMap>();
static {
// Arrays of various types (including common object types)
_arraySerializers.put(boolean[].class.getName(), new ArraySerializers.BooleanArraySerializer());
_arraySerializers.put(byte[].class.getName(), new ArraySerializers.ByteArraySerializer());
_arraySerializers.put(char[].class.getName(), new ArraySerializers.CharArraySerializer());
_arraySerializers.put(short[].class.getName(), new ArraySerializers.ShortArraySerializer());
_arraySerializers.put(int[].class.getName(), new ArraySerializers.IntArraySerializer());
_arraySerializers.put(long[].class.getName(), new ArraySerializers.LongArraySerializer());
_arraySerializers.put(float[].class.getName(), new ArraySerializers.FloatArraySerializer());
_arraySerializers.put(double[].class.getName(), new ArraySerializers.DoubleArraySerializer());
}
/**
* Helper object used to deal with serializers for optional JDK types (like ones
* omitted from GAE, Android)
*/
protected OptionalHandlerFactory optionalHandlers = OptionalHandlerFactory.instance;
/*
/**********************************************************
/* Life cycle
/**********************************************************
*/
/**
* 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
/**********************************************************
*/
// Implemented by sub-classes
@Override
public abstract JsonSerializer