コード例 #1
0
  public ValueInstantiator constructValueInstantiator(DeserializationConfig config) {
    JavaType delegateType;
    boolean maybeVanilla = !_hasNonDefaultCreator;

    if (maybeVanilla || (_creators[C_DELEGATE] == 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;
          }
        }
      }
      delegateType = _creators[C_DELEGATE].getParameterType(ix);
    }

    final JavaType type = _beanDesc.getType();

    // Any non-standard creator will prevent; with one exception: int-valued constructor
    // that standard containers have can be ignored
    maybeVanilla &= !_hasNonDefaultCreator;

    if (maybeVanilla) {
      /* 10-May-2014, tatu: If we have nothing special, and we are dealing with one
       *   of "well-known" types, can create a non-reflection-based instantiator.
       */
      final Class<?> rawType = type.getRawClass();
      if (rawType == Collection.class || rawType == List.class || rawType == ArrayList.class) {
        return new Vanilla(Vanilla.TYPE_COLLECTION);
      }
      if (rawType == Map.class || rawType == LinkedHashMap.class) {
        return new Vanilla(Vanilla.TYPE_MAP);
      }
      if (rawType == HashMap.class) {
        return new Vanilla(Vanilla.TYPE_HASH_MAP);
      }
    }

    StdValueInstantiator inst = new StdValueInstantiator(config, type);
    inst.configureFromObjectSettings(
        _creators[C_DEFAULT],
        _creators[C_DELEGATE],
        delegateType,
        _delegateArgs,
        _creators[C_PROPS],
        _propertyBasedArgs);
    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
0
  protected JavaType materializeAbstractType(DeserializationConfig config, BeanDescription beanDesc)
      throws JsonMappingException {
    final JavaType abstractType = beanDesc.getType();

    /* [JACKSON-502] (1.8): Now it is possible to have multiple resolvers too,
     *   as they are registered via module interface.
     */
    for (AbstractTypeResolver r : _factoryConfig.abstractTypeResolvers()) {
      JavaType concrete = r.resolveAbstractType(config, abstractType);
      if (concrete != null) {
        return concrete;
      }
    }
    return null;
  }