Refine search
public ValueInstantiator constructValueInstantiator(DeserializationContext ctxt) throws JsonMappingException { final DeserializationConfig config = ctxt.getConfig(); final JavaType delegateType = _computeDelegateType(ctxt, _creators[C_DELEGATE], _delegateArgs); final JavaType arrayDelegateType = _computeDelegateType(ctxt, _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]); return inst; }
@Override public Object createFromString(DeserializationContext ctxt, String value) throws IOException { if (_fromStringCreator == null) { return _createFromStringFallbacks(ctxt, value); } try { return _fromStringCreator.call1(value); } catch (Throwable t) { return ctxt.handleInstantiationProblem(_fromStringCreator.getDeclaringClass(), value, rewrapCtorProblem(ctxt, t)); } }
config.constructType(ZoneId.class), config); if (!inst.canCreateFromString()) { AnnotatedMethod factory = _findFactory(ac, "of", String.class); if (factory != null) { inst.configureFromStringCreator(factory);
@Override public boolean canInstantiate() { return canCreateUsingDefault() || canCreateUsingDelegate() || canCreateUsingArrayDelegate() || canCreateFromObjectWith() || canCreateFromString() || canCreateFromInt() || canCreateFromLong() || canCreateFromDouble() || canCreateFromBoolean(); }
@Override public Object createFromDouble(DeserializationContext ctxt, double value) throws IOException { try { if (_fromDoubleCreator != null) { return _fromDoubleCreator.call1(Double.valueOf(value)); } } catch (Exception e) { throw wrapException(e); } catch (ExceptionInInitializerError e) { throw wrapException(e); } throw ctxt.mappingException("Can not instantiate value of type "+getValueTypeDesc() +" from Floating-point number ("+value+"); no one-double/Double-arg constructor/factory method"); }
throw new IllegalStateException("No delegate constructor for "+getValueTypeDesc()); return _delegateCreator.call1(delegate); args[i] = delegate; } else { // nope, injectable: args[i] = ctxt.findInjectableValue(prop.getInjectableValueId(), prop, null); return _delegateCreator.call(args); } catch (ExceptionInInitializerError e) { throw wrapException(e); } catch (Exception e) { throw wrapException(e);
throw new IllegalStateException("No delegate constructor for "+getValueTypeDesc()); return delegateCreator.call1(delegate); args[i] = delegate; } else { // nope, injectable: args[i] = ctxt.findInjectableValue(prop.getInjectableValueId(), prop, null); return delegateCreator.call(args); } catch (Throwable t) { throw rewrapCtorProblem(ctxt, t);
@Override public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) throws IOException { if (_withArgsCreator == null) { // sanity-check; caller should check throw new IllegalStateException("No with-args constructor for "+getValueTypeDesc()); } try { return _withArgsCreator.call(args); } catch (ExceptionInInitializerError e) { throw wrapException(e); } catch (Exception e) { throw wrapException(e); } }
@Override public Object createFromLong(DeserializationContext ctxt, long value) throws IOException, JsonProcessingException { try { if (_fromLongCreator != null) { return _fromLongCreator.call1(Long.valueOf(value)); } } catch (Exception e) { throw wrapException(e); } catch (ExceptionInInitializerError e) { throw wrapException(e); } throw new JsonMappingException("Can not instantiate value of type "+getValueTypeDesc() +" from JSON long integral number; no single-long-arg constructor/factory method"); }
@Override public Object createFromString(DeserializationContext ctxt, String value) throws IOException { if (_fromStringCreator != null) { try { return _fromStringCreator.call1(value); } catch (Exception e) { throw wrapException(e); } catch (ExceptionInInitializerError e) { throw wrapException(e); } } return _createFromStringFallbacks(ctxt, value); }
/** * @deprecated Since 2.7 call either {@link #unwrapAndWrapException} or * {@link #wrapAsJsonMappingException} */ @Deprecated // since 2.7 protected JsonMappingException wrapException(Throwable t) { // 05-Nov-2015, tatu: This used to always unwrap the whole exception, but now only // does so if and until `JsonMappingException` is found. for (Throwable curr = t; curr != null; curr = curr.getCause()) { if (curr instanceof JsonMappingException) { return (JsonMappingException) curr; } } return new JsonMappingException(null, "Instantiation of "+getValueTypeDesc()+" value failed: "+ClassUtil.exceptionMessage(t), t); }
protected Object _createFromStringFallbacks(DeserializationContext ctxt, String value) throws IOException, JsonProcessingException { /* 28-Sep-2011, tatu: Ok this is not clean at all; but since there are legacy * systems that expect conversions in some cases, let's just add a minimal * patch (note: same could conceivably be used for numbers too). */ if (_fromBooleanCreator != null) { String str = value.trim(); if ("true".equals(str)) { return createFromBoolean(ctxt, true); } if ("false".equals(str)) { return createFromBoolean(ctxt, false); } } // and finally, empty Strings might be accepted as null Object... if (_cfgEmptyStringsAsObjects && value.length() == 0) { return null; } throw new JsonMappingException("Can not instantiate value of type "+getValueTypeDesc() +" from String value; no single-String constructor/factory method"); }
@Override public Object createFromBoolean(DeserializationContext ctxt, boolean value) throws IOException { try { if (_fromBooleanCreator != null) { return _fromBooleanCreator.call1(Boolean.valueOf(value)); } } catch (Exception e) { throw wrapException(e); } catch (ExceptionInInitializerError e) { throw wrapException(e); } throw ctxt.mappingException("Can not instantiate value of type "+getValueTypeDesc() +" from Boolean value ("+value+"); no single-boolean/Boolean-arg constructor/factory method"); }
throw new IllegalStateException("No delegate constructor for "+getValueTypeDesc()); return _delegateCreator.call1(delegate); args[i] = delegate; } else { // nope, injectable: args[i] = ctxt.findInjectableValue(prop.getInjectableValueId(), prop, null); return _delegateCreator.call(args); } catch (ExceptionInInitializerError e) { throw wrapException(e); } catch (Exception e) { throw wrapException(e);
throw new IllegalStateException("No delegate constructor for "+getValueTypeDesc()); return delegateCreator.call1(delegate); args[i] = delegate; } else { // nope, injectable: args[i] = ctxt.findInjectableValue(prop.getInjectableValueId(), prop, null); return delegateCreator.call(args); } catch (Throwable t) { throw rewrapCtorProblem(ctxt, t);
@Override public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) throws IOException { if (_withArgsCreator == null) { // sanity-check; caller should check throw new IllegalStateException("No with-args constructor for "+getValueTypeDesc()); } try { return _withArgsCreator.call(args); } catch (ExceptionInInitializerError e) { throw wrapException(e); } catch (Exception e) { throw wrapException(e); } }
@Override public Object createFromBoolean(DeserializationContext ctxt, boolean value) throws IOException, JsonProcessingException { try { if (_fromBooleanCreator != null) { return _fromBooleanCreator.call1(Boolean.valueOf(value)); } } catch (Exception e) { throw wrapException(e); } catch (ExceptionInInitializerError e) { throw wrapException(e); } throw new JsonMappingException("Can not instantiate value of type "+getValueTypeDesc() +" from JSON boolean value; no single-boolean/Boolean-arg constructor/factory method"); }
@Override public boolean canInstantiate() { return canCreateUsingDefault() || canCreateUsingDelegate() || canCreateUsingArrayDelegate() || canCreateFromObjectWith() || canCreateFromString() || canCreateFromInt() || canCreateFromLong() || canCreateFromDouble() || canCreateFromBoolean(); }
@Override public Object createFromString(DeserializationContext ctxt, String value) throws IOException { if (_fromStringCreator != null) { try { return _fromStringCreator.call1(value); } catch (Exception e) { throw wrapException(e); } catch (ExceptionInInitializerError e) { throw wrapException(e); } } return _createFromStringFallbacks(ctxt, value); }
protected JsonMappingException wrapException(Throwable t) { while (t.getCause() != null) { t = t.getCause(); } if (t instanceof JsonMappingException) { return (JsonMappingException) t; } return new JsonMappingException("Instantiation of "+getValueTypeDesc()+" value failed: "+t.getMessage(), t); } }