类com.fasterxml.jackson.databind.deser.ValueInstantiator源码实例Demo

下面列出了怎么用com.fasterxml.jackson.databind.deser.ValueInstantiator的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: PropertyBasedCreator.java
/**
 * Factory method used for building actual instances to be used with POJOS:
 * resolves deserializers, checks for "null values".
 *
 * @since 2.9
 */
public static PropertyBasedCreator construct(DeserializationContext ctxt,
        ValueInstantiator valueInstantiator, SettableBeanProperty[] srcCreatorProps,
        BeanPropertyMap allProperties)
    throws JsonMappingException
{
    final int len = srcCreatorProps.length;
    SettableBeanProperty[] creatorProps = new SettableBeanProperty[len];
    for (int i = 0; i < len; ++i) {
        SettableBeanProperty prop = srcCreatorProps[i];
        if (!prop.hasValueDeserializer()) {
            prop = prop.withValueDeserializer(ctxt.findContextualValueDeserializer(prop.getType(), prop));
        }
        creatorProps[i] = prop;
    }
    return new PropertyBasedCreator(ctxt, valueInstantiator, creatorProps,
            allProperties.isCaseInsensitive(),
            allProperties.hasAliases());
}
 
源代码2 项目: lams   文件: PropertyBasedCreator.java
/**
 * Factory method used for building actual instances to be used with types
 * OTHER than POJOs.
 * resolves deserializers and checks for "null values".
 *
 * @since 2.9
 */
public static PropertyBasedCreator construct(DeserializationContext ctxt,
        ValueInstantiator valueInstantiator, SettableBeanProperty[] srcCreatorProps,
        boolean caseInsensitive)
    throws JsonMappingException
{
    final int len = srcCreatorProps.length;
    SettableBeanProperty[] creatorProps = new SettableBeanProperty[len];
    for (int i = 0; i < len; ++i) {
        SettableBeanProperty prop = srcCreatorProps[i];
        if (!prop.hasValueDeserializer()) {
            prop = prop.withValueDeserializer(ctxt.findContextualValueDeserializer(prop.getType(), prop));
        }
        creatorProps[i] = prop;
    }
    return new PropertyBasedCreator(ctxt, valueInstantiator, creatorProps, 
            caseInsensitive, false);
}
 
源代码3 项目: caravan   文件: MapDeserializerManager.java
public MapDeserializerManager(MapCustomizationFactory factory) {
  /**
   * The first parameter is just a placeholder, won't be used.
   * So any element type is ok.
   */
  super(
      CollectionType.construct(ArrayList.class, null, null, null, //
          SimpleType.constructUnsafe(Object.class)), //
      null, null, new ValueInstantiator() {
        @SuppressWarnings("rawtypes")
        @Override
        public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
          return new ArrayList();
        }
      });

  this.factory = factory;
}
 
@SuppressWarnings("unused") // Used from PairInstantiatorsPopulator
static <P> ValueInstantiator primitiveObjectInstantiator(
        JavaType inputType, Class<?> one,
        BiFunction<Object, Object, P> factory
) {
    return new ValueInstantiator.Base(inputType) {
        @Override
        public boolean canCreateFromObjectWith() {
            return true;
        }

        @Override
        public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) {
            JavaType oneType = config.constructType(one);
            JavaType twoType = inputType.containedType(0);
            return makeProperties(config, oneType, twoType);
        }

        @Override
        public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) {
            return factory.apply(args[0], args[1]);
        }
    };
}
 
@SuppressWarnings("unused") // Used from PairInstantiatorsPopulator
static <P> ValueInstantiator objectPrimitiveInstantiator(
        JavaType inputType, Class<?> two,
        BiFunction<Object, Object, P> factory
) {
    return new ValueInstantiator.Base(inputType) {
        @Override
        public boolean canCreateFromObjectWith() {
            return true;
        }

        @Override
        public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) {
            JavaType oneType = inputType.containedType(0);
            JavaType twoType = config.constructType(two);
            return makeProperties(config, oneType, twoType);
        }

        @Override
        public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) {
            return factory.apply(args[0], args[1]);
        }
    };
}
 
@SuppressWarnings("unused") // Used from PairInstantiatorsPopulator
static <P> void purePrimitiveInstantiator(
        Class<P> pairClass, Class<?> one, Class<?> two,
        BiFunction<Object, Object, P> factory
) {
    PURE_PRIMITIVE_INSTANTIATORS.put(pairClass, new ValueInstantiator.Base(pairClass) {
        @Override
        public boolean canCreateFromObjectWith() {
            return true;
        }

        @Override
        public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) {
            JavaType oneType = config.constructType(one);
            JavaType twoType = config.constructType(two);
            return makeProperties(config, oneType, twoType);
        }

        @Override
        public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) {
            return factory.apply(args[0], args[1]);
        }
    });
}
 
/** @since 4.3 */
@Override
public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ValueInstantiator) this.beanFactory.createBean(implClass);
}
 
/** @since 4.3 */
@Override
public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ValueInstantiator) this.beanFactory.createBean(implClass);
}
 
源代码9 项目: lams   文件: SimpleModule.java
/**
 * Method for registering {@link ValueInstantiator} to use when deserializing
 * instances of type <code>beanType</code>.
 *<p>
 * Instantiator is
 * registered when module is registered for <code>ObjectMapper</code>.
 */
public SimpleModule addValueInstantiator(Class<?> beanType, ValueInstantiator inst)
{
    _checkNotNull(beanType, "class to register value instantiator for");
    _checkNotNull(inst, "value instantiator");
    if (_valueInstantiators == null) {
        _valueInstantiators = new SimpleValueInstantiators();
    }
    _valueInstantiators = _valueInstantiators.addValueInstantiator(beanType, inst);
    return this;
}
 
源代码10 项目: lams   文件: SimpleValueInstantiators.java
@Override
public ValueInstantiator findValueInstantiator(DeserializationConfig config,
        BeanDescription beanDesc, ValueInstantiator defaultInstantiator)
{
    ValueInstantiator inst = _classMappings.get(new ClassKey(beanDesc.getBeanClass()));
    return (inst == null) ? defaultInstantiator : inst;
}
 
源代码11 项目: lams   文件: ReferenceTypeDeserializer.java
@SuppressWarnings("unchecked")
public ReferenceTypeDeserializer(JavaType fullType, ValueInstantiator vi,
        TypeDeserializer typeDeser, JsonDeserializer<?> deser)
{
    super(fullType);
    _valueInstantiator = vi;
    _fullType = fullType;
    _valueDeserializer = (JsonDeserializer<Object>) deser;
    _valueTypeDeserializer = typeDeser;
}
 
源代码12 项目: lams   文件: StringCollectionDeserializer.java
@SuppressWarnings("unchecked")
protected StringCollectionDeserializer(JavaType collectionType,
        ValueInstantiator valueInstantiator, JsonDeserializer<?> delegateDeser,
        JsonDeserializer<?> valueDeser,
        NullValueProvider nuller, Boolean unwrapSingle)
{
    super(collectionType, nuller, unwrapSingle);
    _valueDeserializer = (JsonDeserializer<String>) valueDeser;
    _valueInstantiator = valueInstantiator;
    _delegateDeserializer = (JsonDeserializer<Object>) delegateDeser;
}
 
源代码13 项目: lams   文件: EnumMapDeserializer.java
/**
 * @since 2.9
 */
public EnumMapDeserializer(JavaType mapType, ValueInstantiator valueInst,
        KeyDeserializer keyDeser, JsonDeserializer<?> valueDeser, TypeDeserializer vtd,
        NullValueProvider nuller)
{
    super(mapType, nuller, null);
    _enumClass = mapType.getKeyType().getRawClass();
    _keyDeserializer = keyDeser;
    _valueDeserializer = (JsonDeserializer<Object>) valueDeser;
    _valueTypeDeserializer = vtd;
    _valueInstantiator = valueInst;
}
 
源代码14 项目: lams   文件: ContainerDeserializerBase.java
@Override // since 2.9
public Object getEmptyValue(DeserializationContext ctxt) throws JsonMappingException {
    ValueInstantiator vi = getValueInstantiator();
    if (vi == null || !vi.canCreateUsingDefault()) {
        JavaType type = getValueType();
        ctxt.reportBadDefinition(type,
                String.format("Cannot create empty instance of %s, no default Creator", type));
    }
    try {
        return vi.createUsingDefault(ctxt);
    } catch (IOException e) {
        return ClassUtil.throwAsMappingException(ctxt, e);
    }
}
 
源代码15 项目: lams   文件: EnumDeserializer.java
/**
 * Factory method used when Enum instances are to be deserialized
 * using a creator (static factory method)
 * 
 * @return Deserializer based on given factory method
 *
 * @since 2.8
 */
public static JsonDeserializer<?> deserializerForCreator(DeserializationConfig config,
        Class<?> enumClass, AnnotatedMethod factory,
        ValueInstantiator valueInstantiator, SettableBeanProperty[] creatorProps)
{
    if (config.canOverrideAccessModifiers()) {
        ClassUtil.checkAndFixAccess(factory.getMember(),
                config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
    }
    return new FactoryBasedEnumDeserializer(enumClass, factory,
            factory.getParameterType(0),
            valueInstantiator, creatorProps);
}
 
源代码16 项目: lams   文件: ArrayBlockingQueueDeserializer.java
/**
 * Constructor used when creating contextualized instances.
 */
 protected ArrayBlockingQueueDeserializer(JavaType containerType,
        JsonDeserializer<Object> valueDeser, TypeDeserializer valueTypeDeser,
        ValueInstantiator valueInstantiator,
        JsonDeserializer<Object> delegateDeser,
        NullValueProvider nuller, Boolean unwrapSingle)
{
    super(containerType, valueDeser, valueTypeDeser, valueInstantiator, delegateDeser,
            nuller, unwrapSingle);
}
 
源代码17 项目: lams   文件: FactoryBasedEnumDeserializer.java
public FactoryBasedEnumDeserializer(Class<?> cls, AnnotatedMethod f, JavaType paramType,
        ValueInstantiator valueInstantiator, SettableBeanProperty[] creatorProps)
{
    super(cls);
    _factory = f;
    _hasArgs = true;
    // We'll skip case of `String`, as well as no type (zero-args): 
    _inputType = paramType.hasRawClass(String.class) ? null : paramType;
    _deser = null;
    _valueInstantiator = valueInstantiator;
    _creatorProps = creatorProps;
}
 
源代码18 项目: lams   文件: PropertyBasedCreator.java
@Deprecated // since 2.9
public static PropertyBasedCreator construct(DeserializationContext ctxt,
        ValueInstantiator valueInstantiator, SettableBeanProperty[] srcCreatorProps)
    throws JsonMappingException
{
    return construct(ctxt, valueInstantiator, srcCreatorProps,
            ctxt.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES));
}
 
源代码19 项目: lams   文件: CreatorCollector.java
public ValueInstantiator constructValueInstantiator(
        DeserializationConfig config) {
    final JavaType delegateType = _computeDelegateType(
            _creators[C_DELEGATE], _delegateArgs);
    final JavaType arrayDelegateType = _computeDelegateType(
            _creators[C_ARRAY_DELEGATE], _arrayDelegateArgs);
    final JavaType type = _beanDesc.getType();

    // 11-Jul-2016, tatu: Earlier optimization by replacing the whole
    // instantiator did not
    // work well, so let's replace by lower-level check:
    AnnotatedWithParams defaultCtor = StdTypeConstructor
            .tryToOptimize(_creators[C_DEFAULT]);

    StdValueInstantiator inst = new StdValueInstantiator(config, type);
    inst.configureFromObjectSettings(defaultCtor, _creators[C_DELEGATE],
            delegateType, _delegateArgs, _creators[C_PROPS],
            _propertyBasedArgs);
    inst.configureFromArraySettings(_creators[C_ARRAY_DELEGATE],
            arrayDelegateType, _arrayDelegateArgs);
    inst.configureFromStringCreator(_creators[C_STRING]);
    inst.configureFromIntCreator(_creators[C_INT]);
    inst.configureFromLongCreator(_creators[C_LONG]);
    inst.configureFromDoubleCreator(_creators[C_DOUBLE]);
    inst.configureFromBooleanCreator(_creators[C_BOOLEAN]);
    inst.configureIncompleteParameter(_incompleteParameter);
    return inst;
}
 
源代码20 项目: caravan   文件: CustomCollectionDeserializer.java
/**
 * Constructor used when creating contextualized instances.
 *
 * @since 2.9
 */
protected CustomCollectionDeserializer(JavaType collectionType,
    JsonDeserializer<Object> valueDeser, TypeDeserializer valueTypeDeser,
    ValueInstantiator valueInstantiator, JsonDeserializer<Object> delegateDeser,
    NullValueProvider nuller, Boolean unwrapSingle) {
  super(collectionType, nuller, unwrapSingle);
  _valueDeserializer = valueDeser;
  _valueTypeDeserializer = valueTypeDeser;
  _valueInstantiator = valueInstantiator;
  _delegateDeserializer = delegateDeser;
}
 
源代码21 项目: caravan   文件: MapDeserializer.java
public MapDeserializer(JavaType pairType) {
  super(
      CollectionType.construct(ArrayList.class, null, null, null, pairType), //
      null, null, new ValueInstantiator() {
        @Override
        public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
          return new ArrayList();
        }
      });
}
 
源代码22 项目: jackson-modules-base   文件: CreatorOptimizer.java
public ValueInstantiator createOptimized()
{
    /* [Issue#11]: Need to avoid optimizing if we use delegate- or
     *  property-based creators.
     */
    if (_originalInstantiator.canCreateFromObjectWith()
            || _originalInstantiator.canCreateUsingDelegate()) {
        return null;
    }
    
    // for now, only consider need to handle default creator
    AnnotatedWithParams defaultCreator = _originalInstantiator.getDefaultCreator();
    if (defaultCreator != null) {
        AnnotatedElement elem = defaultCreator.getAnnotated();
        if (elem instanceof Constructor<?>) {
            // First things first: as per [Issue#34], can NOT access private ctors or methods
            Constructor<?> ctor = (Constructor<?>) elem;
            if (!Modifier.isPrivate(ctor.getModifiers())) {
                return createSubclass(ctor, null).with(_originalInstantiator);
            }
        } else if (elem instanceof Method) {
            Method m = (Method) elem;
            int mods = m.getModifiers();
            // and as above, can't access private ones
            if (Modifier.isStatic(mods) && !Modifier.isPrivate(mods)) {
                return createSubclass(null, m).with(_originalInstantiator);
            }
        }
    }
    return null;
}
 
源代码23 项目: jackson-modules-base   文件: ProblemHandlerTest.java
@Override
public Object handleMissingInstantiator(DeserializationContext ctxt,
        Class<?> instClass, ValueInstantiator inst, JsonParser p, String msg)
    throws IOException
{
    p.skipChildren();
    return value;
}
 
源代码24 项目: lams   文件: SpringHandlerInstantiator.java
/** @since 4.3 */
@Override
public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
	return (ValueInstantiator) this.beanFactory.createBean(implClass);
}
 
源代码25 项目: lams   文件: HandlerInstantiator.java
/**
 * Method called to construct an instance of ValueInstantiator of specified type.
 */
public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> config,
        Annotated annotated, Class<?> resolverClass) {
    return null;
}
 
源代码26 项目: lams   文件: SimpleValueInstantiators.java
public SimpleValueInstantiators()
{
    _classMappings = new HashMap<ClassKey,ValueInstantiator>();        
}
 
源代码27 项目: lams   文件: SimpleValueInstantiators.java
public SimpleValueInstantiators addValueInstantiator(Class<?> forType,
        ValueInstantiator inst)
{
    _classMappings.put(new ClassKey(forType), inst);
    return this;
}
 
源代码28 项目: lams   文件: StringCollectionDeserializer.java
public StringCollectionDeserializer(JavaType collectionType,
        JsonDeserializer<?> valueDeser, ValueInstantiator valueInstantiator)
{
    this(collectionType, valueInstantiator, null, valueDeser, valueDeser, null);
}
 
源代码29 项目: lams   文件: StringCollectionDeserializer.java
@Override
public ValueInstantiator getValueInstantiator() {
    return _valueInstantiator;
}
 
源代码30 项目: lams   文件: StdDeserializer.java
protected final NullValueProvider _findNullProvider(DeserializationContext ctxt,
        BeanProperty prop, Nulls nulls, JsonDeserializer<?> valueDeser)
    throws JsonMappingException
{
    if (nulls == Nulls.FAIL) {
        if (prop == null) {
            return NullsFailProvider.constructForRootValue(ctxt.constructType(valueDeser.handledType()));
        }
        return NullsFailProvider.constructForProperty(prop);
    }
    if (nulls == Nulls.AS_EMPTY) {
        // cannot deal with empty values if there is no value deserializer that
        // can indicate what "empty value" is:
        if (valueDeser == null) {
            return null;
        }

        // Let's first do some sanity checking...
        // NOTE: although we could use `ValueInstantiator.Gettable` in general,
        // let's not since that would prevent being able to use custom impls:
        if (valueDeser instanceof BeanDeserializerBase) {
            ValueInstantiator vi = ((BeanDeserializerBase) valueDeser).getValueInstantiator();
            if (!vi.canCreateUsingDefault()) {
                final JavaType type = prop.getType();
                ctxt.reportBadDefinition(type,
                        String.format("Cannot create empty instance of %s, no default Creator", type));
            }
        }
        // Second: can with pre-fetch value?
        {
            AccessPattern access = valueDeser.getEmptyAccessPattern();
            if (access == AccessPattern.ALWAYS_NULL) {
                return NullsConstantProvider.nuller();
            }
            if (access == AccessPattern.CONSTANT) {
                return NullsConstantProvider.forValue(valueDeser.getEmptyValue(ctxt));
            }
        }
        return new NullsAsEmptyProvider(valueDeser);
    }
    if (nulls == Nulls.SKIP) {
        return NullsConstantProvider.skipper();
    }
    return null;
}
 
 类方法
 同包方法