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.util.*;
import org.codehaus.jackson.map.*;
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.std.MapSerializer;
import org.codehaus.jackson.map.type.*;
import org.codehaus.jackson.map.util.ArrayBuilders;
import org.codehaus.jackson.map.util.ClassUtil;
import org.codehaus.jackson.type.JavaType;
/**
* Factory class that can provide serializers for any regular Java beans
* (as defined by "having at least one get method recognizable as bean
* accessor" -- where {@link Object#getClass} does not count);
* as well as for "standard" JDK types. Latter is achieved
* by delegating calls to {@link BasicSerializerFactory}
* to find serializers both for "standard" JDK types (and in some cases,
* sub-classes as is the case for collection classes like
* {@link java.util.List}s and {@link java.util.Map}s) and bean (value)
* classes.
*
* Note about delegating calls to {@link BasicSerializerFactory}:
* although it would be nicer to use linear delegation
* for construction (to essentially dispatch all calls first to the
* underlying {@link BasicSerializerFactory}; or alternatively after
* failing to provide bean-based serializer}, there is a problem:
* priority levels for detecting standard types are mixed. That is,
* we want to check if a type is a bean after some of "standard" JDK
* types, but before the rest.
* As a result, "mixed" delegation used, and calls are NOT done using
* regular {@link SerializerFactory} interface but rather via
* direct calls to {@link BasicSerializerFactory}.
*
* Finally, since all caching is handled by the serializer provider
* (not factory) and there is no configurability, this
* factory is stateless.
* This means that a global singleton instance can be used.
*
* Notes for version 1.7 (and above): the new module registration system
* required addition of {@link #withConfig}, which has to
* be redefined by sub-classes so that they can work properly with
* pluggable additional serializer providing components.
*/
public class BeanSerializerFactory
extends BasicSerializerFactory
{
/**
* Like {@link BasicSerializerFactory}, this factory is stateless, and
* thus a single shared global (== singleton) instance can be used
* without thread-safety issues.
*/
public final static BeanSerializerFactory instance = new BeanSerializerFactory(null);
/**
* Configuration settings for this factory; immutable instance (just like this
* factory), new version created via copy-constructor (fluent-style)
*
* @since 1.7
*/
protected final Config _factoryConfig;
/*
/**********************************************************
/* Config class implementation
/**********************************************************
*/
/**
* Configuration settings container class for bean serializer factory
*
* @since 1.7
*/
public static class ConfigImpl extends Config
{
/**
* Constant for empty Serializers array (which by definition
* is stateless and reusable)
*/
protected final static Serializers[] NO_SERIALIZERS = new Serializers[0];
protected final static BeanSerializerModifier[] NO_MODIFIERS = new BeanSerializerModifier[0];
/**
* List of providers for additional serializers, checked before considering default
* basic or bean serialializers.
*
* @since 1.7
*/
protected final Serializers[] _additionalSerializers;
/**
* @since 1.8
*/
protected final Serializers[] _additionalKeySerializers;
/**
* List of modifiers that can change the way {@link BeanSerializer} instances
* are configured and constructed.
*/
protected final BeanSerializerModifier[] _modifiers;
public ConfigImpl() {
this(null, null, null);
}
protected ConfigImpl(Serializers[] allAdditionalSerializers,
Serializers[] allAdditionalKeySerializers,
BeanSerializerModifier[] modifiers)
{
_additionalSerializers = (allAdditionalSerializers == null) ?
NO_SERIALIZERS : allAdditionalSerializers;
_additionalKeySerializers = (allAdditionalKeySerializers == null) ?
NO_SERIALIZERS : allAdditionalKeySerializers;
_modifiers = (modifiers == null) ? NO_MODIFIERS : modifiers;
}
@Override
public Config withAdditionalSerializers(Serializers additional)
{
if (additional == null) {
throw new IllegalArgumentException("Can not pass null Serializers");
}
Serializers[] all = ArrayBuilders.insertInListNoDup(_additionalSerializers, additional);
return new ConfigImpl(all, _additionalKeySerializers, _modifiers);
}
@Override
public Config withAdditionalKeySerializers(Serializers additional)
{
if (additional == null) {
throw new IllegalArgumentException("Can not pass null Serializers");
}
Serializers[] all = ArrayBuilders.insertInListNoDup(_additionalKeySerializers, additional);
return new ConfigImpl(_additionalSerializers, all, _modifiers);
}
@Override
public Config withSerializerModifier(BeanSerializerModifier modifier)
{
if (modifier == null) {
throw new IllegalArgumentException("Can not pass null modifier");
}
BeanSerializerModifier[] modifiers = ArrayBuilders.insertInListNoDup(_modifiers, modifier);
return new ConfigImpl(_additionalSerializers, _additionalKeySerializers, modifiers);
}
@Override
public boolean hasSerializers() { return _additionalSerializers.length > 0; }
@Override
public boolean hasKeySerializers() { return _additionalKeySerializers.length > 0; }
@Override
public boolean hasSerializerModifiers() { return _modifiers.length > 0; }
@Override
public Iterable serializers() {
return ArrayBuilders.arrayAsIterable(_additionalSerializers);
}
@Override
public Iterable keySerializers() {
return ArrayBuilders.arrayAsIterable(_additionalKeySerializers);
}
@Override
public Iterable serializerModifiers() {
return ArrayBuilders.arrayAsIterable(_modifiers);
}
}
/*
/**********************************************************
/* Life-cycle: creation, configuration
/**********************************************************
*/
/**
* Constructor for creating instances with specified configuration.
*/
protected BeanSerializerFactory(Config config)
{
if (config == null) {
config = new ConfigImpl();
}
_factoryConfig = config;
}
@Override public Config getConfig() { return _factoryConfig; }
/**
* Method used by module registration functionality, to attach additional
* serializer providers into this serializer factory. This is typically
* handled by constructing a new instance with additional serializers,
* to ensure thread-safe access.
*
* @since 1.7
*/
@Override
public SerializerFactory withConfig(Config config)
{
if (_factoryConfig == config) {
return this;
}
/* 22-Nov-2010, tatu: Handling of subtypes is tricky if we do immutable-with-copy-ctor;
* and we pretty much have to here either choose between losing subtype instance
* when registering additional serializers, or losing serializers.
* Instead, let's actually just throw an error if this method is called when subtype
* has not properly overridden this method; this to indicate problem as soon as possible.
*/
if (getClass() != BeanSerializerFactory.class) {
throw new IllegalStateException("Subtype of BeanSerializerFactory ("+getClass().getName()
+") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with "
+"additional serializer definitions");
}
return new BeanSerializerFactory(config);
}
@Override
protected Iterable customSerializers() {
return _factoryConfig.serializers();
}
/*
/**********************************************************
/* SerializerFactory impl
/**********************************************************
*/
/**
* Main serializer constructor method. We will have to be careful
* with respect to ordering of various method calls: essentially
* we want to reliably figure out which classes are standard types,
* and which are beans. The problem is that some bean Classes may
* implement standard interfaces (say, {@link java.lang.Iterable}.
*
* Note: sub-classes may choose to complete replace implementation,
* if they want to alter priority of serializer lookups.
*/
@Override
@SuppressWarnings("unchecked")
public JsonSerializer