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

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

源代码1 项目: 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;
}
 
源代码2 项目: jackson-modules-base   文件: CreatorOptimizer.java
public CreatorOptimizer(Class<?> valueClass, MyClassLoader classLoader,
        StdValueInstantiator orig)
{
    _valueClass = valueClass;
    _classLoader = classLoader;
    _originalInstantiator = orig;
}
 
源代码3 项目: nexus-public   文件: NpmMergeObjectMapper.java
@Override
protected void deserialize(final NestedAttributesMapJsonParser parser,
                           final DeserializationContext context,
                           final MapDeserializer rootDeserializer) throws IOException
{
  StdValueInstantiator instantiator = (StdValueInstantiator) rootDeserializer.getValueInstantiator();

  SourceMapDeserializer.of(rootDeserializer.getValueType(),
      new NestedAttributesMapStdValueInstantiator(instantiator, parser.getRoot()),
      new NpmNestedAttributesMapUntypedObjectDeserializer(parser))
      .deserialize(parser, context);
}
 
源代码4 项目: nexus-public   文件: MergeObjectMapper.java
protected void deserialize(final NestedAttributesMapJsonParser parser,
                           final DeserializationContext context,
                           final MapDeserializer rootDeserializer)
    throws IOException
{
  StdValueInstantiator instantiator = (StdValueInstantiator) rootDeserializer.getValueInstantiator();

  SourceMapDeserializer.of(rootDeserializer.getValueType(),
      new NestedAttributesMapStdValueInstantiator(instantiator, parser.getRoot()),
      new NestedAttributesMapUntypedObjectDeserializer(parser))
      .deserialize(parser, context);
}
 
@Override
public BeanDeserializerBuilder updateBuilder(DeserializationConfig config,
        BeanDescription beanDesc, BeanDeserializerBuilder builder) 
{
    final Class<?> beanClass = beanDesc.getBeanClass();
    // [module-afterburner#21]: Can't force access to sealed packages, or anything within "java."
    if (!MyClassLoader.canAddClassInPackageOf(beanClass)) {
        return builder;
    } 
    /* Hmmh. Can we access stuff from private classes?
     * Possibly, if we can use parent class loader.
     * (should probably skip all non-public?)
     */
    if (_classLoader != null) {
        if (Modifier.isPrivate(beanClass.getModifiers())) {
            return builder;
        }
    }
    PropertyMutatorCollector collector = new PropertyMutatorCollector(beanClass);
    List<OptimizedSettableBeanProperty<?>> newProps = findOptimizableProperties(
            config, collector, builder.getProperties());
    // and if we found any, create mutator proxy, replace property objects
    if (!newProps.isEmpty()) {
        BeanPropertyMutator baseMutator = collector.buildMutator(_classLoader);
        for (OptimizedSettableBeanProperty<?> prop : newProps) {
            builder.addOrReplaceProperty(prop.withMutator(baseMutator), true);
        }
    }
    // Second thing: see if we could (re)generate Creator(s):
    ValueInstantiator inst = builder.getValueInstantiator();
    /* Hmmh. Probably better to require exact default implementation
     * and not sub-class; chances are sub-class uses its own
     * construction anyway.
     */
    if (inst.getClass() == StdValueInstantiator.class) {
        // also, only override if using default creator (no-arg ctor, no-arg static factory)
        if (inst.canCreateUsingDefault()) {
            inst = new CreatorOptimizer(beanClass, _classLoader, (StdValueInstantiator) inst).createOptimized();
            if (inst != null) {
                builder.setValueInstantiator(inst);
            }
        }
    }

    // also: may want to replace actual BeanDeserializer as well? For this, need to replace builder
    // (but only if builder is the original standard one; don't want to break other impls)
    if (_useCustomDeserializer && builder.getClass() == BeanDeserializerBuilder.class) {
        return new SuperSonicDeserializerBuilder(builder);
    }
    return builder;
}
 
/**
 * Copy-constructor to use for creating actual optimized instances.
 */
protected OptimizedValueInstantiator(StdValueInstantiator src) {
    super(src);
}
 
public NestedAttributesMapStdValueInstantiator(final StdValueInstantiator src, final NestedAttributesMap root) {
  super(checkNotNull(src));
  this.root = checkNotNull(root);
}
 
源代码8 项目: bootique   文件: BQTimeModule.java
@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;
        }
    });
}
 
protected abstract OptimizedValueInstantiator with(StdValueInstantiator src); 
 类方法
 同包方法