@Override public Object handleMissingInstantiator(DeserializationContext ctxt, Class<?> instClass, ValueInstantiator valueInsta, JsonParser p, String msg) throws IOException { /* FIXME: For some reason Jackson can't find the {@link Canvas(String)} constructor, so we do it ourselves: * 1. Check if the deserializer bails out on a JSON string * 2. Find a String-constructor on the target class * 3. Build the object */ if (p.getCurrentToken() == JsonToken.VALUE_STRING) { } try { // Special case for empty strings in collection fields. if (p.getValueAsString().isEmpty() && Collection.class.isAssignableFrom(instClass)) { return instClass.getConstructor().newInstance(); } else { Constructor<?> constructor = instClass.getConstructor(String.class); return constructor.newInstance(p.getValueAsString()); } } catch (Exception e) { // Fall through } return super.handleMissingInstantiator(ctxt, instClass, valueInsta, p, msg); }
protected PropertyBasedCreator(ValueInstantiator paramValueInstantiator, SettableBeanProperty[] paramArrayOfSettableBeanProperty, Object[] paramArrayOfObject) { this._valueInstantiator = paramValueInstantiator; this._properties = new HashMap(); SettableBeanProperty[] arrayOfSettableBeanProperty = null; int i = paramArrayOfSettableBeanProperty.length; this._propertyCount = i; for (int j = 0; j < i; j++) { SettableBeanProperty localSettableBeanProperty = paramArrayOfSettableBeanProperty[j]; this._properties.put(localSettableBeanProperty.getName(), localSettableBeanProperty); if (localSettableBeanProperty.getInjectableValueId() != null) { if (arrayOfSettableBeanProperty == null) arrayOfSettableBeanProperty = new SettableBeanProperty[i]; arrayOfSettableBeanProperty[j] = localSettableBeanProperty; } } this._defaultValues = paramArrayOfObject; this._propertiesWithInjectables = arrayOfSettableBeanProperty; }
public static <T> T deserializeNodeForCollection(JsonParser jp, DeserializationContext ctxt, JavaType javaType) throws IOException, JsonProcessingException { if (jp.isExpectedStartArrayToken()) { JsonNode jsonNode = jp.readValueAs(JsonNode.class); T result = XML_MAPPER.reader(javaType).readValue(jsonNode); return result; } else if (jp.getCurrentToken() == JsonToken.VALUE_STRING) { String str = jp.getText(); if (StringUtils.isEmpty(StringUtils.trimAllWhitespace(str))) { // TODO: cleanup final DeserializationConfig config = ctxt.getConfig(); BeanDescription beanDesc = config.introspect(javaType); boolean fixAccess = ctxt.canOverrideAccessModifiers(); CreatorCollector creators = new CreatorCollector(beanDesc, fixAccess); ValueInstantiator valueInstantiator = creators.constructValueInstantiator(config); return (T) valueInstantiator.createUsingDefault(ctxt); } } throw ctxt.mappingException("Expected XML element"); }
protected PropertyBasedCreator(ValueInstantiator valueInstantiator, SettableBeanProperty[] creatorProps, Object[] defaultValues) { _valueInstantiator = valueInstantiator; _properties = new HashMap<String, SettableBeanProperty>(); SettableBeanProperty[] propertiesWithInjectables = null; final int len = creatorProps.length; _propertyCount = len; for (int i = 0; i < len; ++i) { SettableBeanProperty prop = creatorProps[i]; _properties.put(prop.getName(), prop); Object injectableValueId = prop.getInjectableValueId(); if (injectableValueId != null) { if (propertiesWithInjectables == null) { propertiesWithInjectables = new SettableBeanProperty[len]; } propertiesWithInjectables[i] = prop; } } _defaultValues = defaultValues; _propertiesWithInjectables = propertiesWithInjectables; }
@Override public ValueInstantiator findValueInstantiator(DeserializationConfig config, BeanDescription beanDesc, ValueInstantiator defaultInstantiator) { if (DEFAULT_NO_DESER_CLASS_NAMES.contains(beanDesc.getClassInfo().getRawType().getName())) { throw new IllegalArgumentException("Illegal type " + beanDesc.getClassInfo().getRawType().getName() + " to deserialize: prevented for security reasons"); } return super.findValueInstantiator(config, beanDesc, defaultInstantiator); }
@Override public void setupModule(SetupContext context) { super.setupModule(context); context.addValueInstantiators(new ValueInstantiators.Base() { @Override public ValueInstantiator findValueInstantiator(DeserializationConfig config, BeanDescription beanDesc, ValueInstantiator defaultInstantiator) { Class<?> raw = beanDesc.getBeanClass(); // 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 = AnnotatedClass.construct(ZoneId.class, null, null); } 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; } }); }
public SimpleModule addValueInstantiator(Class<?> paramClass, ValueInstantiator paramValueInstantiator) { if (this._valueInstantiators == null) this._valueInstantiators = new SimpleValueInstantiators(); this._valueInstantiators = this._valueInstantiators.addValueInstantiator(paramClass, paramValueInstantiator); return this; }
public ValueInstantiator findValueInstantiator(DeserializationConfig paramDeserializationConfig, BeanDescription paramBeanDescription, ValueInstantiator paramValueInstantiator) { ValueInstantiator localValueInstantiator = (ValueInstantiator)this._classMappings.get(new ClassKey(paramBeanDescription.getBeanClass())); if (localValueInstantiator == null) return paramValueInstantiator; return localValueInstantiator; }
public MapDeserializer(JavaType paramJavaType, ValueInstantiator paramValueInstantiator, KeyDeserializer paramKeyDeserializer, JsonDeserializer<Object> paramJsonDeserializer, TypeDeserializer paramTypeDeserializer) { super(Map.class); this._mapType = paramJavaType; this._keyDeserializer = paramKeyDeserializer; this._valueDeserializer = paramJsonDeserializer; this._valueTypeDeserializer = paramTypeDeserializer; this._valueInstantiator = paramValueInstantiator; this._hasDefaultCreator = paramValueInstantiator.canCreateUsingDefault(); this._delegateDeserializer = null; this._propertyBasedCreator = null; this._standardStringKey = _isStdKeyDeser(paramJavaType, paramKeyDeserializer); }
protected StringCollectionDeserializer(JavaType paramJavaType, ValueInstantiator paramValueInstantiator, JsonDeserializer<?> paramJsonDeserializer1, JsonDeserializer<?> paramJsonDeserializer2) { super(paramJavaType.getRawClass()); this._collectionType = paramJavaType; this._valueDeserializer = paramJsonDeserializer2; this._valueInstantiator = paramValueInstantiator; this._delegateDeserializer = paramJsonDeserializer1; }
public final JsonDeserializer<?> createContextual(DeserializationContext paramDeserializationContext, BeanProperty paramBeanProperty) { ValueInstantiator localValueInstantiator = this._valueInstantiator; JsonDeserializer localJsonDeserializer1 = null; if (localValueInstantiator != null) { AnnotatedWithParams localAnnotatedWithParams = this._valueInstantiator.getDelegateCreator(); localJsonDeserializer1 = null; if (localAnnotatedWithParams != null) localJsonDeserializer1 = findDeserializer(paramDeserializationContext, this._valueInstantiator.getDelegateType(paramDeserializationContext.getConfig()), paramBeanProperty); } JsonDeserializer localJsonDeserializer2 = this._valueDeserializer; Object localObject = localJsonDeserializer2; if (localJsonDeserializer2 == null) { JsonDeserializer localJsonDeserializer3 = findConvertingContentDeserializer(paramDeserializationContext, paramBeanProperty, (JsonDeserializer)localObject); localObject = localJsonDeserializer3; if (localJsonDeserializer3 == null) localObject = paramDeserializationContext.findContextualValueDeserializer(this._collectionType.getContentType(), paramBeanProperty); } else if ((localObject instanceof ContextualDeserializer)) { localObject = ((ContextualDeserializer)localObject).createContextual(paramDeserializationContext, paramBeanProperty); } if (isDefaultDeserializer((JsonDeserializer)localObject)) localObject = null; return withResolved(localJsonDeserializer1, (JsonDeserializer)localObject); }
protected CollectionDeserializer(JavaType paramJavaType, JsonDeserializer<Object> paramJsonDeserializer1, TypeDeserializer paramTypeDeserializer, ValueInstantiator paramValueInstantiator, JsonDeserializer<Object> paramJsonDeserializer2) { super(paramJavaType.getRawClass()); this._collectionType = paramJavaType; this._valueDeserializer = paramJsonDeserializer1; this._valueTypeDeserializer = paramTypeDeserializer; this._valueInstantiator = paramValueInstantiator; this._delegateDeserializer = paramJsonDeserializer2; }
public CollectionDeserializer createContextual(DeserializationContext paramDeserializationContext, BeanProperty paramBeanProperty) { ValueInstantiator localValueInstantiator = this._valueInstantiator; JsonDeserializer localJsonDeserializer1 = null; if (localValueInstantiator != null) { boolean bool = this._valueInstantiator.canCreateUsingDelegate(); localJsonDeserializer1 = null; if (bool) { JavaType localJavaType = this._valueInstantiator.getDelegateType(paramDeserializationContext.getConfig()); if (localJavaType == null) throw new IllegalArgumentException("Invalid delegate-creator definition for " + this._collectionType + ": value instantiator (" + this._valueInstantiator.getClass().getName() + ") returned true for 'canCreateUsingDelegate()', but null for 'getDelegateType()'"); localJsonDeserializer1 = findDeserializer(paramDeserializationContext, localJavaType, paramBeanProperty); } } JsonDeserializer localJsonDeserializer2 = findConvertingContentDeserializer(paramDeserializationContext, paramBeanProperty, this._valueDeserializer); JsonDeserializer localJsonDeserializer3 = localJsonDeserializer2; if (localJsonDeserializer2 == null) localJsonDeserializer3 = paramDeserializationContext.findContextualValueDeserializer(this._collectionType.getContentType(), paramBeanProperty); else if ((localJsonDeserializer3 instanceof ContextualDeserializer)) localJsonDeserializer3 = ((ContextualDeserializer)localJsonDeserializer3).createContextual(paramDeserializationContext, paramBeanProperty); TypeDeserializer localTypeDeserializer1 = this._valueTypeDeserializer; TypeDeserializer localTypeDeserializer2 = localTypeDeserializer1; if (localTypeDeserializer1 != null) localTypeDeserializer2 = localTypeDeserializer2.forProperty(paramBeanProperty); return withResolved(localJsonDeserializer1, localJsonDeserializer3, localTypeDeserializer2); }
public static PropertyBasedCreator construct(DeserializationContext paramDeserializationContext, ValueInstantiator paramValueInstantiator, SettableBeanProperty[] paramArrayOfSettableBeanProperty) { int i = paramArrayOfSettableBeanProperty.length; SettableBeanProperty[] arrayOfSettableBeanProperty = new SettableBeanProperty[i]; Object[] arrayOfObject = null; for (int j = 0; j < i; j++) { SettableBeanProperty localSettableBeanProperty1 = paramArrayOfSettableBeanProperty[j]; SettableBeanProperty localSettableBeanProperty2 = localSettableBeanProperty1; if (!localSettableBeanProperty1.hasValueDeserializer()) localSettableBeanProperty2 = localSettableBeanProperty2.withValueDeserializer(paramDeserializationContext.findContextualValueDeserializer(localSettableBeanProperty2.getType(), localSettableBeanProperty2)); arrayOfSettableBeanProperty[j] = localSettableBeanProperty2; JsonDeserializer localJsonDeserializer = localSettableBeanProperty2.getValueDeserializer(); Object localObject1; if (localJsonDeserializer == null) localObject1 = null; else localObject1 = localJsonDeserializer.getNullValue(); Object localObject2 = localObject1; if ((localObject1 == null) && (localSettableBeanProperty2.getType().isPrimitive())) localObject2 = ClassUtil.defaultValue(localSettableBeanProperty2.getType().getRawClass()); if (localObject2 != null) { if (arrayOfObject == null) arrayOfObject = new Object[i]; arrayOfObject[j] = localObject2; } } return new PropertyBasedCreator(paramValueInstantiator, arrayOfSettableBeanProperty, arrayOfObject); }
public ValueInstantiator constructValueInstantiator(DeserializationConfig paramDeserializationConfig) { StdValueInstantiator localStdValueInstantiator = new StdValueInstantiator(paramDeserializationConfig, this._beanDesc.getType()); JavaType localJavaType; if (this._delegateCreator == null) { localJavaType = null; } else { CreatorProperty[] arrayOfCreatorProperty = this._delegateArgs; int i = 0; if (arrayOfCreatorProperty != null) { int j = 0; int k = this._delegateArgs.length; while (true) { i = 0; if (j >= k) break; if (this._delegateArgs[j] == null) { i = j; break; } j++; } } localJavaType = this._beanDesc.bindingsForBeanType().resolveType(this._delegateCreator.getGenericParameterType(i)); } localStdValueInstantiator.configureFromObjectSettings(this._defaultConstructor, this._delegateCreator, localJavaType, this._delegateArgs, this._propertyBasedCreator, this._propertyBasedArgs); localStdValueInstantiator.configureFromStringCreator(this._stringCreator); localStdValueInstantiator.configureFromIntCreator(this._intCreator); localStdValueInstantiator.configureFromLongCreator(this._longCreator); localStdValueInstantiator.configureFromDoubleCreator(this._doubleCreator); localStdValueInstantiator.configureFromBooleanCreator(this._booleanCreator); localStdValueInstantiator.configureIncompleteParameter(this._incompleteParameter); return localStdValueInstantiator; }
/** * 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) { if (_valueInstantiators == null) { _valueInstantiators = new SimpleValueInstantiators(); } _valueInstantiators = _valueInstantiators.addValueInstantiator(beanType, inst); return this; }
@Override public ValueInstantiator findValueInstantiator(DeserializationConfig config, BeanDescription beanDesc, ValueInstantiator defaultInstantiator) { ValueInstantiator inst = _classMappings.get(new ClassKey(beanDesc.getBeanClass())); return (inst == null) ? defaultInstantiator : inst; }
@SuppressWarnings("unchecked") protected StringCollectionDeserializer(JavaType collectionType, ValueInstantiator valueInstantiator, JsonDeserializer<?> delegateDeser, JsonDeserializer<?> valueDeser) { super(collectionType.getRawClass()); _collectionType = collectionType; _valueDeserializer = (JsonDeserializer<String>) valueDeser; _valueInstantiator = valueInstantiator; _delegateDeserializer = (JsonDeserializer<Object>) delegateDeser; }
/** * Constructor for context-free instances, where we do not yet know * which property is using this deserializer. */ public CollectionDeserializer(JavaType collectionType, JsonDeserializer<Object> valueDeser, TypeDeserializer valueTypeDeser, ValueInstantiator valueInstantiator) { this(collectionType, valueDeser, valueTypeDeser, valueInstantiator, null); }
/** * Constructor used when creating contextualized instances. */ protected CollectionDeserializer(JavaType collectionType, JsonDeserializer<Object> valueDeser, TypeDeserializer valueTypeDeser, ValueInstantiator valueInstantiator, JsonDeserializer<Object> delegateDeser) { super(collectionType.getRawClass()); _collectionType = collectionType; _valueDeserializer = valueDeser; _valueTypeDeserializer = valueTypeDeser; _valueInstantiator = valueInstantiator; _delegateDeserializer = delegateDeser; }
public static ValueInstantiator findValueInstantiator(DeserializationConfig config, BeanDescription beanDesc) { if (beanDesc.getBeanClass() == JsonLocation.class) { return new JsonLocationInstantiator(); } return null; }
/** * Factory method used for building actual instances: resolves deserializers * and checks for "null values". */ public static PropertyBasedCreator construct(DeserializationContext ctxt, ValueInstantiator valueInstantiator, SettableBeanProperty[] srcProps) throws JsonMappingException { final int len = srcProps.length; SettableBeanProperty[] creatorProps = new SettableBeanProperty[len]; Object[] defaultValues = null; for (int i = 0; i < len; ++i) { SettableBeanProperty prop = srcProps[i]; if (!prop.hasValueDeserializer()) { prop = prop.withValueDeserializer(ctxt.findContextualValueDeserializer(prop.getType(), prop)); } creatorProps[i] = prop; // [JACKSON-372]: primitive types need extra care // [JACKSON-774]: as do non-default nulls... JsonDeserializer<?> deser = prop.getValueDeserializer(); Object nullValue = (deser == null) ? null : deser.getNullValue(); if ((nullValue == null) && prop.getType().isPrimitive()) { nullValue = ClassUtil.defaultValue(prop.getType().getRawClass()); } if (nullValue != null) { if (defaultValues == null) { defaultValues = new Object[len]; } defaultValues[i] = nullValue; } } return new PropertyBasedCreator(valueInstantiator, creatorProps, defaultValues); }
public ValueInstantiator constructValueInstantiator(DeserializationConfig config) { StdValueInstantiator inst = new StdValueInstantiator(config, _beanDesc.getType()); JavaType delegateType; if (_delegateCreator == 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; } } } TypeBindings bindings = _beanDesc.bindingsForBeanType(); delegateType = bindings.resolveType(_delegateCreator.getGenericParameterType(ix)); } inst.configureFromObjectSettings(_defaultConstructor, _delegateCreator, delegateType, _delegateArgs, _propertyBasedCreator, _propertyBasedArgs); inst.configureFromStringCreator(_stringCreator); inst.configureFromIntCreator(_intCreator); inst.configureFromLongCreator(_longCreator); inst.configureFromDoubleCreator(_doubleCreator); inst.configureFromBooleanCreator(_booleanCreator); return inst; }
@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; } }); }
public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> paramMapperConfig, Annotated paramAnnotated, Class<?> paramClass) { return null; }
public SimpleValueInstantiators addValueInstantiator(Class<?> paramClass, ValueInstantiator paramValueInstantiator) { this._classMappings.put(new ClassKey(paramClass), paramValueInstantiator); return this; }
public StringCollectionDeserializer(JavaType paramJavaType, JsonDeserializer<?> paramJsonDeserializer, ValueInstantiator paramValueInstantiator) { this(paramJavaType, paramValueInstantiator, null, paramJsonDeserializer); }
public CollectionDeserializer(JavaType paramJavaType, JsonDeserializer<Object> paramJsonDeserializer, TypeDeserializer paramTypeDeserializer, ValueInstantiator paramValueInstantiator) { this(paramJavaType, paramJsonDeserializer, paramTypeDeserializer, paramValueInstantiator, null); }
public ArrayBlockingQueueDeserializer(JavaType paramJavaType, JsonDeserializer<Object> paramJsonDeserializer1, TypeDeserializer paramTypeDeserializer, ValueInstantiator paramValueInstantiator, JsonDeserializer<Object> paramJsonDeserializer2) { super(paramJavaType, paramJsonDeserializer1, paramTypeDeserializer, paramValueInstantiator, paramJsonDeserializer2); }
public static ValueInstantiator findValueInstantiator(DeserializationConfig paramDeserializationConfig, BeanDescription paramBeanDescription) { if (paramBeanDescription.getBeanClass() == JsonLocation.class) return JsonLocationInstantiator.instance; return null; }
/** * Method called to construct an instance of ValueInstantiator of specified type. */ public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> config, Annotated annotated, Class<?> resolverClass) { return null; }
public SimpleValueInstantiators() { _classMappings = new HashMap<ClassKey,ValueInstantiator>(); }
public SimpleValueInstantiators addValueInstantiator(Class<?> forType, ValueInstantiator inst) { _classMappings.put(new ClassKey(forType), inst); return this; }
public StringCollectionDeserializer(JavaType collectionType, JsonDeserializer<?> valueDeser, ValueInstantiator valueInstantiator) { this(collectionType, valueInstantiator, null, valueDeser); }