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.deser;
import java.util.*;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.*;
import org.codehaus.jackson.map.deser.impl.CreatorCollector;
import org.codehaus.jackson.map.deser.impl.CreatorProperty;
import org.codehaus.jackson.map.deser.std.StdKeyDeserializers;
import org.codehaus.jackson.map.deser.std.ThrowableDeserializer;
import org.codehaus.jackson.map.introspect.*;
import org.codehaus.jackson.map.type.*;
import org.codehaus.jackson.map.util.ArrayBuilders;
import org.codehaus.jackson.map.util.ClassUtil;
import org.codehaus.jackson.map.util.EnumResolver;
import org.codehaus.jackson.type.JavaType;
/**
* Concrete deserializer factory class that adds full Bean deserializer
* construction logic using class introspection.
*
* Since there is no caching, this factory is stateless and a globally
* shared singleton instance ({@link #instance}) can be used by
* {@link DeserializerProvider}s).
*/
public class BeanDeserializerFactory
extends BasicDeserializerFactory
{
/**
* Signature of Throwable.initCause method.
*/
private final static Class>[] INIT_CAUSE_PARAMS = new Class>[] { Throwable.class };
/*
/**********************************************************
/* Config class implementation
/**********************************************************
*/
/**
* Standard configuration settings container class implementation.
*
* @since 1.7
*/
public static class ConfigImpl extends Config
{
protected final static KeyDeserializers[] NO_KEY_DESERIALIZERS = new KeyDeserializers[0];
protected final static BeanDeserializerModifier[] NO_MODIFIERS = new BeanDeserializerModifier[0];
protected final static AbstractTypeResolver[] NO_ABSTRACT_TYPE_RESOLVERS = new AbstractTypeResolver[0];
protected final static ValueInstantiators[] NO_VALUE_INSTANTIATORS = new ValueInstantiators[0];
/**
* List of providers for additional deserializers, checked before considering default
* basic or bean deserializers.
*
* @since 1.7
*/
protected final Deserializers[] _additionalDeserializers;
/**
* List of providers for additional key deserializers, checked before considering
* standard key deserializers.
*
* @since 1.7
*/
protected final KeyDeserializers[] _additionalKeyDeserializers;
/**
* List of modifiers that can change the way {@link BeanDeserializer} instances
* are configured and constructed.
*/
protected final BeanDeserializerModifier[] _modifiers;
/**
* List of objects that may be able to resolve abstract types to
* concrete types. Used by functionality like "mr Bean" to materialize
* types as needed.
*
* @since 1.8
*/
protected final AbstractTypeResolver[] _abstractTypeResolvers;
/**
* List of objects that know how to create instances of POJO types;
* possibly using custom construction (non-annoted constructors; factory
* methods external to value type etc).
* Used to support objects that are created using non-standard methods;
* or to support post-constructor functionality.
*
* @since 1.9
*/
protected final ValueInstantiators[] _valueInstantiators;
/**
* Constructor for creating basic configuration with no additional
* handlers.
*/
public ConfigImpl() {
this(null, null, null, null, null);
}
/**
* Copy-constructor that will create an instance that contains defined
* set of additional deserializer providers.
*/
protected ConfigImpl(Deserializers[] allAdditionalDeserializers,
KeyDeserializers[] allAdditionalKeyDeserializers,
BeanDeserializerModifier[] modifiers,
AbstractTypeResolver[] atr,
ValueInstantiators[] vi)
{
_additionalDeserializers = (allAdditionalDeserializers == null) ?
NO_DESERIALIZERS : allAdditionalDeserializers;
_additionalKeyDeserializers = (allAdditionalKeyDeserializers == null) ?
NO_KEY_DESERIALIZERS : allAdditionalKeyDeserializers;
_modifiers = (modifiers == null) ? NO_MODIFIERS : modifiers;
_abstractTypeResolvers = (atr == null) ? NO_ABSTRACT_TYPE_RESOLVERS : atr;
_valueInstantiators = (vi == null) ? NO_VALUE_INSTANTIATORS : vi;
}
@Override
public Config withAdditionalDeserializers(Deserializers additional)
{
if (additional == null) {
throw new IllegalArgumentException("Can not pass null Deserializers");
}
Deserializers[] all = ArrayBuilders.insertInListNoDup(_additionalDeserializers, additional);
return new ConfigImpl(all, _additionalKeyDeserializers, _modifiers,
_abstractTypeResolvers, _valueInstantiators);
}
@Override
public Config withAdditionalKeyDeserializers(KeyDeserializers additional)
{
if (additional == null) {
throw new IllegalArgumentException("Can not pass null KeyDeserializers");
}
KeyDeserializers[] all = ArrayBuilders.insertInListNoDup(_additionalKeyDeserializers, additional);
return new ConfigImpl(_additionalDeserializers, all, _modifiers,
_abstractTypeResolvers, _valueInstantiators);
}
@Override
public Config withDeserializerModifier(BeanDeserializerModifier modifier)
{
if (modifier == null) {
throw new IllegalArgumentException("Can not pass null modifier");
}
BeanDeserializerModifier[] all = ArrayBuilders.insertInListNoDup(_modifiers, modifier);
return new ConfigImpl(_additionalDeserializers, _additionalKeyDeserializers, all,
_abstractTypeResolvers, _valueInstantiators);
}
@Override
public Config withAbstractTypeResolver(AbstractTypeResolver resolver)
{
if (resolver == null) {
throw new IllegalArgumentException("Can not pass null resolver");
}
AbstractTypeResolver[] all = ArrayBuilders.insertInListNoDup(_abstractTypeResolvers, resolver);
return new ConfigImpl(_additionalDeserializers, _additionalKeyDeserializers, _modifiers,
all, _valueInstantiators);
}
@Override
public Config withValueInstantiators(ValueInstantiators instantiators)
{
if (instantiators == null) {
throw new IllegalArgumentException("Can not pass null resolver");
}
ValueInstantiators[] all = ArrayBuilders.insertInListNoDup(_valueInstantiators, instantiators);
return new ConfigImpl(_additionalDeserializers, _additionalKeyDeserializers, _modifiers,
_abstractTypeResolvers, all);
}
@Override
public boolean hasDeserializers() { return _additionalDeserializers.length > 0; }
@Override
public boolean hasKeyDeserializers() { return _additionalKeyDeserializers.length > 0; }
@Override
public boolean hasDeserializerModifiers() { return _modifiers.length > 0; }
@Override
public boolean hasAbstractTypeResolvers() { return _abstractTypeResolvers.length > 0; }
@Override
public boolean hasValueInstantiators() { return _valueInstantiators.length > 0; }
@Override
public Iterable deserializers() {
return ArrayBuilders.arrayAsIterable(_additionalDeserializers);
}
@Override
public Iterable keyDeserializers() {
return ArrayBuilders.arrayAsIterable(_additionalKeyDeserializers);
}
@Override
public Iterable deserializerModifiers() {
return ArrayBuilders.arrayAsIterable(_modifiers);
}
@Override
public Iterable abstractTypeResolvers() {
return ArrayBuilders.arrayAsIterable(_abstractTypeResolvers);
}
@Override
public Iterable valueInstantiators() {
return ArrayBuilders.arrayAsIterable(_valueInstantiators);
}
}
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
/**
* Globally shareable thread-safe instance which has no additional custom deserializers
* registered
*/
public final static BeanDeserializerFactory instance = new BeanDeserializerFactory(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;
@Deprecated
public BeanDeserializerFactory() {
this(null);
}
/**
* @since 1.7
*/
public BeanDeserializerFactory(DeserializerFactory.Config config) {
if (config == null) {
config = new ConfigImpl();
}
_factoryConfig = config;
}
@Override
public final Config getConfig() {
return _factoryConfig;
}
/**
* Method used by module registration functionality, to construct a new bean
* deserializer factory
* with different configuration settings.
*
* @since 1.7
*/
@Override
public DeserializerFactory withConfig(DeserializerFactory.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 deserializers, or losing deserializers.
* 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() != BeanDeserializerFactory.class) {
throw new IllegalStateException("Subtype of BeanDeserializerFactory ("+getClass().getName()
+") has not properly overridden method 'withAdditionalDeserializers': can not instantiate subtype with "
+"additional deserializer definitions");
}
return new BeanDeserializerFactory(config);
}
/*
/**********************************************************
/* Overrides for super-class methods used for finding
/* custom deserializers
/**********************************************************
*/
@Override
public KeyDeserializer createKeyDeserializer(DeserializationConfig config, JavaType type,
BeanProperty property)
throws JsonMappingException
{
// First: possible custom deserializers
if (_factoryConfig.hasKeyDeserializers()) {
BasicBeanDescription beanDesc = config.introspectClassAnnotations(type.getRawClass());
for (KeyDeserializers d : _factoryConfig.keyDeserializers()) {
KeyDeserializer deser = d.findKeyDeserializer(type, config, beanDesc, property);
if (deser != null) {
return deser;
}
}
}
// and if none found, standard ones:
// No serializer needed if it's plain old String, or Object/untyped
Class> raw = type.getRawClass();
if (raw == String.class || raw == Object.class) {
return StdKeyDeserializers.constructStringKeyDeserializer(config, type);
}
// Most other keys are of limited number of static types
KeyDeserializer kdes = _keyDeserializers.get(type);
if (kdes != null) {
return kdes;
}
// And then other one-offs; first, Enum:
if (type.isEnumType()) {
return _createEnumKeyDeserializer(config, type, property);
}
// One more thing: can we find ctor(String) or valueOf(String)?
kdes = StdKeyDeserializers.findStringBasedKeyDeserializer(config, type);
return kdes;
}
private KeyDeserializer _createEnumKeyDeserializer(DeserializationConfig config, JavaType type,
BeanProperty property)
throws JsonMappingException
{
BasicBeanDescription beanDesc = config.introspect(type);
Class> enumClass = type.getRawClass();
EnumResolver> enumRes = constructEnumResolver(enumClass, config);
// [JACKSON-193] May have @JsonCreator for static factory method:
for (AnnotatedMethod factory : beanDesc.getFactoryMethods()) {
if (config.getAnnotationIntrospector().hasCreatorAnnotation(factory)) {
int argCount = factory.getParameterCount();
if (argCount == 1) {
Class> returnType = factory.getRawType();
// usually should be class, but may be just plain Enum> (for Enum.valueOf()?)
if (returnType.isAssignableFrom(enumClass)) {
// note: mostly copied from 'EnumDeserializer.deserializerForCreator(...)'
if (factory.getParameterType(0) != String.class) {
throw new IllegalArgumentException("Parameter #0 type for factory method ("+factory+") not suitable, must be java.lang.String");
}
if (config.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(factory.getMember());
}
return StdKeyDeserializers.constructEnumKeyDeserializer(enumRes, factory);
}
}
throw new IllegalArgumentException("Unsuitable method ("+factory+") decorated with @JsonCreator (for Enum type "
+enumClass.getName()+")");
}
}
// [JACKSON-749] Also, need to consider @JsonValue, if one found
return StdKeyDeserializers.constructEnumKeyDeserializer(enumRes);
}
@Override
protected JsonDeserializer> _findCustomArrayDeserializer(ArrayType type, DeserializationConfig config,
DeserializerProvider provider,
BeanProperty property,
TypeDeserializer elementTypeDeserializer, JsonDeserializer> elementDeserializer)
throws JsonMappingException
{
for (Deserializers d : _factoryConfig.deserializers()) {
JsonDeserializer> deser = d.findArrayDeserializer(type, config, provider, property,
elementTypeDeserializer, elementDeserializer);
if (deser != null) {
return deser;
}
}
return null;
}
@Override
protected JsonDeserializer> _findCustomCollectionDeserializer(CollectionType type, DeserializationConfig config,
DeserializerProvider provider, BasicBeanDescription beanDesc,
BeanProperty property,
TypeDeserializer elementTypeDeserializer, JsonDeserializer> elementDeserializer)
throws JsonMappingException
{
for (Deserializers d : _factoryConfig.deserializers()) {
JsonDeserializer> deser = d.findCollectionDeserializer(type, config, provider, beanDesc, property,
elementTypeDeserializer, elementDeserializer);
if (deser != null) {
return deser;
}
}
return null;
}
@Override
protected JsonDeserializer> _findCustomCollectionLikeDeserializer(CollectionLikeType type, DeserializationConfig config,
DeserializerProvider provider, BasicBeanDescription beanDesc,
BeanProperty property,
TypeDeserializer elementTypeDeserializer, JsonDeserializer> elementDeserializer)
throws JsonMappingException
{
for (Deserializers d : _factoryConfig.deserializers()) {
JsonDeserializer> deser = d.findCollectionLikeDeserializer(type, config, provider, beanDesc, property,
elementTypeDeserializer, elementDeserializer);
if (deser != null) {
return deser;
}
}
return null;
}
@Override
protected JsonDeserializer> _findCustomEnumDeserializer(Class> type, DeserializationConfig config,
BasicBeanDescription beanDesc, BeanProperty property)
throws JsonMappingException
{
for (Deserializers d : _factoryConfig.deserializers()) {
JsonDeserializer> deser = d.findEnumDeserializer(type, config, beanDesc, property);
if (deser != null) {
return deser;
}
}
return null;
}
@Override
protected JsonDeserializer> _findCustomMapDeserializer(MapType type,
DeserializationConfig config,
DeserializerProvider provider, BasicBeanDescription beanDesc, BeanProperty property,
KeyDeserializer keyDeserializer,
TypeDeserializer elementTypeDeserializer, JsonDeserializer> elementDeserializer)
throws JsonMappingException
{
for (Deserializers d : _factoryConfig.deserializers()) {
JsonDeserializer> deser = d.findMapDeserializer(type, config, provider, beanDesc, property,
keyDeserializer, elementTypeDeserializer, elementDeserializer);
if (deser != null) {
return deser;
}
}
return null;
}
@Override
protected JsonDeserializer> _findCustomMapLikeDeserializer(MapLikeType type,
DeserializationConfig config,
DeserializerProvider provider, BasicBeanDescription beanDesc, BeanProperty property,
KeyDeserializer keyDeserializer,
TypeDeserializer elementTypeDeserializer, JsonDeserializer> elementDeserializer)
throws JsonMappingException
{
for (Deserializers d : _factoryConfig.deserializers()) {
JsonDeserializer> deser = d.findMapLikeDeserializer(type, config, provider, beanDesc, property,
keyDeserializer, elementTypeDeserializer, elementDeserializer);
if (deser != null) {
return deser;
}
}
return null;
}
@Override
protected JsonDeserializer> _findCustomTreeNodeDeserializer(Class extends JsonNode> type,
DeserializationConfig config, BeanProperty property)
throws JsonMappingException
{
for (Deserializers d : _factoryConfig.deserializers()) {
JsonDeserializer> deser = d.findTreeNodeDeserializer(type, config, property);
if (deser != null) {
return deser;
}
}
return null;
}
// Note: NOT overriding, superclass has no matching method
@SuppressWarnings("unchecked")
protected JsonDeserializer