com.fasterxml.jackson.databind.deser.std.StdValueInstantiator Java Examples

The following examples show how to use com.fasterxml.jackson.databind.deser.std.StdValueInstantiator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreatorCollector.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #2
Source File: CreatorOptimizer.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public CreatorOptimizer(Class<?> valueClass, MyClassLoader classLoader,
        StdValueInstantiator orig)
{
    _valueClass = valueClass;
    _classLoader = classLoader;
    _originalInstantiator = orig;
}
 
Example #3
Source File: NpmMergeObjectMapper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@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);
}
 
Example #4
Source File: MergeObjectMapper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: ABDeserializerModifier.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example #6
Source File: OptimizedValueInstantiator.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
/**
 * Copy-constructor to use for creating actual optimized instances.
 */
protected OptimizedValueInstantiator(StdValueInstantiator src) {
    super(src);
}
 
Example #7
Source File: NestedAttributesMapStdValueInstantiator.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public NestedAttributesMapStdValueInstantiator(final StdValueInstantiator src, final NestedAttributesMap root) {
  super(checkNotNull(src));
  this.root = checkNotNull(root);
}
 
Example #8
Source File: BQTimeModule.java    From bootique with Apache License 2.0 4 votes vote down vote up
@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;
        }
    });
}
 
Example #9
Source File: OptimizedValueInstantiator.java    From jackson-modules-base with Apache License 2.0 votes vote down vote up
protected abstract OptimizedValueInstantiator with(StdValueInstantiator src);