@Override public void setupModule(SetupContext context) { super.setupModule(context); context.addValueInstantiators(new ValueInstantiators.Base() { @Override public ValueInstantiator findValueInstantiator(DeserializationConfig config, BeanDescription beanDesc, ValueInstantiator defaultInstantiator) { Class<?> raw = beanDesc.getBeanClass(); // 15-May-2015, tatu: In theory not safe, but in practice we do need to do "fuzzy" matching // because we will (for now) be getting a subtype, but in future may want to downgrade // to the common base type. Even more, serializer may purposefully force use of base type. // So... in practice it really should always work, in the end. :) if (ZoneId.class.isAssignableFrom(raw)) { // let's assume we should be getting "empty" StdValueInstantiator here: if (defaultInstantiator instanceof StdValueInstantiator) { StdValueInstantiator inst = (StdValueInstantiator) defaultInstantiator; // one further complication: we need ZoneId info, not sub-class AnnotatedClass ac; if (raw == ZoneId.class) { ac = beanDesc.getClassInfo(); } else { // we don't need Annotations, so constructing directly is fine here // even if it's not generally recommended ac = AnnotatedClass.construct(ZoneId.class, null, null); } if (!inst.canCreateFromString()) { AnnotatedMethod factory = _findFactory(ac, "of", String.class); if (factory != null) { inst.configureFromStringCreator(factory); } // otherwise... should we indicate an error? } // return ZoneIdInstantiator.construct(config, beanDesc, defaultInstantiator); } } return defaultInstantiator; } }); }
protected DeserializerFactoryConfig(Deserializers[] paramArrayOfDeserializers, KeyDeserializers[] paramArrayOfKeyDeserializers, BeanDeserializerModifier[] paramArrayOfBeanDeserializerModifier, AbstractTypeResolver[] paramArrayOfAbstractTypeResolver, ValueInstantiators[] paramArrayOfValueInstantiators) { Deserializers[] arrayOfDeserializers; if (paramArrayOfDeserializers == null) arrayOfDeserializers = NO_DESERIALIZERS; else arrayOfDeserializers = paramArrayOfDeserializers; this._additionalDeserializers = arrayOfDeserializers; KeyDeserializers[] arrayOfKeyDeserializers; if (paramArrayOfKeyDeserializers == null) arrayOfKeyDeserializers = DEFAULT_KEY_DESERIALIZERS; else arrayOfKeyDeserializers = paramArrayOfKeyDeserializers; this._additionalKeyDeserializers = arrayOfKeyDeserializers; BeanDeserializerModifier[] arrayOfBeanDeserializerModifier; if (paramArrayOfBeanDeserializerModifier == null) arrayOfBeanDeserializerModifier = NO_MODIFIERS; else arrayOfBeanDeserializerModifier = paramArrayOfBeanDeserializerModifier; this._modifiers = arrayOfBeanDeserializerModifier; AbstractTypeResolver[] arrayOfAbstractTypeResolver; if (paramArrayOfAbstractTypeResolver == null) arrayOfAbstractTypeResolver = NO_ABSTRACT_TYPE_RESOLVERS; else arrayOfAbstractTypeResolver = paramArrayOfAbstractTypeResolver; this._abstractTypeResolvers = arrayOfAbstractTypeResolver; ValueInstantiators[] arrayOfValueInstantiators; if (paramArrayOfValueInstantiators == null) arrayOfValueInstantiators = NO_VALUE_INSTANTIATORS; else arrayOfValueInstantiators = paramArrayOfValueInstantiators; this._valueInstantiators = arrayOfValueInstantiators; }
public DeserializerFactoryConfig withValueInstantiators(ValueInstantiators paramValueInstantiators) { if (paramValueInstantiators == null) throw new IllegalArgumentException("Can not pass null resolver"); ValueInstantiators[] arrayOfValueInstantiators = (ValueInstantiators[])ArrayBuilders.insertInListNoDup(this._valueInstantiators, paramValueInstantiators); return new DeserializerFactoryConfig(this._additionalDeserializers, this._additionalKeyDeserializers, this._modifiers, this._abstractTypeResolvers, arrayOfValueInstantiators); }
@Override public void setupModule(SetupContext context) { super.setupModule(context); context.addValueInstantiators(new ValueInstantiators.Base() { @Override public ValueInstantiator findValueInstantiator(DeserializationConfig config, BeanDescription beanDesc, ValueInstantiator defaultInstantiator) { JavaType type = beanDesc.getType(); Class<?> raw = type.getRawClass(); // 15-May-2015, tatu: In theory not safe, but in practice we do need to do "fuzzy" matching // because we will (for now) be getting a subtype, but in future may want to downgrade // to the common base type. Even more, serializer may purposefully force use of base type. // So... in practice it really should always work, in the end. :) if (ZoneId.class.isAssignableFrom(raw)) { // let's assume we should be getting "empty" StdValueInstantiator here: if (defaultInstantiator instanceof StdValueInstantiator) { StdValueInstantiator inst = (StdValueInstantiator) defaultInstantiator; // one further complication: we need ZoneId info, not sub-class AnnotatedClass ac; if (raw == ZoneId.class) { ac = beanDesc.getClassInfo(); } else { // we don't need Annotations, so constructing directly is fine here // even if it's not generally recommended ac = AnnotatedClassResolver.resolve(config, config.constructType(ZoneId.class), config); } if (!inst.canCreateFromString()) { AnnotatedMethod factory = _findFactory(ac, "of", String.class); if (factory != null) { inst.configureFromStringCreator(factory); } // otherwise... should we indicate an error? } // return ZoneIdInstantiator.construct(config, beanDesc, defaultInstantiator); } } return defaultInstantiator; } }); }
public Iterable<ValueInstantiators> valueInstantiators() { return ArrayBuilders.arrayAsIterable(this._valueInstantiators); }
/** * Method that module can use to register additional {@link com.fasterxml.jackson.databind.deser.ValueInstantiator}s, * by adding {@link ValueInstantiators} object that gets called when * instantatiator is needed by a deserializer. * * @param instantiators Object that can provide {@link com.fasterxml.jackson.databind.deser.ValueInstantiator}s for * constructing POJO values during deserialization */ public void addValueInstantiators(ValueInstantiators instantiators);
public abstract void addValueInstantiators(ValueInstantiators paramValueInstantiators);