@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; } }); }
public ValueInstantiator constructValueInstantiator(DeserializationConfig paramDeserializationConfig) { StdValueInstantiator localStdValueInstantiator = new StdValueInstantiator(paramDeserializationConfig, this._beanDesc.getType()); JavaType localJavaType; if (this._delegateCreator == null) { localJavaType = null; } else { CreatorProperty[] arrayOfCreatorProperty = this._delegateArgs; int i = 0; if (arrayOfCreatorProperty != null) { int j = 0; int k = this._delegateArgs.length; while (true) { i = 0; if (j >= k) break; if (this._delegateArgs[j] == null) { i = j; break; } j++; } } localJavaType = this._beanDesc.bindingsForBeanType().resolveType(this._delegateCreator.getGenericParameterType(i)); } localStdValueInstantiator.configureFromObjectSettings(this._defaultConstructor, this._delegateCreator, localJavaType, this._delegateArgs, this._propertyBasedCreator, this._propertyBasedArgs); localStdValueInstantiator.configureFromStringCreator(this._stringCreator); localStdValueInstantiator.configureFromIntCreator(this._intCreator); localStdValueInstantiator.configureFromLongCreator(this._longCreator); localStdValueInstantiator.configureFromDoubleCreator(this._doubleCreator); localStdValueInstantiator.configureFromBooleanCreator(this._booleanCreator); localStdValueInstantiator.configureIncompleteParameter(this._incompleteParameter); return localStdValueInstantiator; }
public ValueInstantiator constructValueInstantiator(DeserializationConfig config) { StdValueInstantiator inst = new StdValueInstantiator(config, _beanDesc.getType()); JavaType delegateType; if (_delegateCreator == null) { delegateType = null; } else { // need to find type... int ix = 0; if (_delegateArgs != null) { for (int i = 0, len = _delegateArgs.length; i < len; ++i) { if (_delegateArgs[i] == null) { // marker for delegate itself ix = i; break; } } } TypeBindings bindings = _beanDesc.bindingsForBeanType(); delegateType = bindings.resolveType(_delegateCreator.getGenericParameterType(ix)); } inst.configureFromObjectSettings(_defaultConstructor, _delegateCreator, delegateType, _delegateArgs, _propertyBasedCreator, _propertyBasedArgs); inst.configureFromStringCreator(_stringCreator); inst.configureFromIntCreator(_intCreator); inst.configureFromLongCreator(_longCreator); inst.configureFromDoubleCreator(_doubleCreator); inst.configureFromBooleanCreator(_booleanCreator); return inst; }
@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; } }); }