aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/fasterxml/jackson/databind
diff options
context:
space:
mode:
authorTatu Saloranta <tsaloranta@gmail.com>2011-12-27 22:34:55 -0800
committerTatu Saloranta <tsaloranta@gmail.com>2011-12-27 22:34:55 -0800
commit289b58d10604feb7b709b91da6d314e0d6ac3b5d (patch)
tree1cc516cd5e704437495d02ce1351b0d1473bf5bc /src/main/java/com/fasterxml/jackson/databind
parent79a126ba58df304da0e5c2eb7a7a4874fadea118 (diff)
downloadjackson-databind-289b58d10604feb7b709b91da6d314e0d6ac3b5d.tar.gz
Improve ValueInstantiator interface to pass enough information to properly construct types (i.e. give DeserializationConfig)
Diffstat (limited to 'src/main/java/com/fasterxml/jackson/databind')
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java56
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBuilder.java19
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java13
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/ValueInstantiator.java10
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyBasedCreator.java6
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/std/CollectionDeserializer.java2
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/std/JacksonDeserializers.java16
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java19
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java11
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/std/StringCollectionDeserializer.java2
10 files changed, 64 insertions, 90 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java
index 3af6c7e04..0b9834c62 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java
@@ -82,8 +82,9 @@ public class BeanDeserializer
* or factory method
* that takes one or more named properties as argument(s),
* this creator is used for instantiation.
+ * This value gets resolved during general resolution.
*/
- protected final PropertyBasedCreator _propertyBasedCreator;
+ protected PropertyBasedCreator _propertyBasedCreator;
/**
* Flag that is set to mark "non-standard" cases; where either
@@ -101,8 +102,6 @@ public class BeanDeserializer
/**
* Mapping of property names to properties, built when all properties
* to use have been successfully resolved.
- *
- * @since 1.7
*/
final protected BeanPropertyMap _beanProperties;
@@ -111,8 +110,6 @@ public class BeanDeserializer
* expected by the bean; otherwise null.
* This includes injectors used for injecting values via setters
* and fields, but not ones passed through constructor parameters.
- *
- * @since 1.9
*/
final protected ValueInjector[] _injectables;
@@ -157,8 +154,6 @@ public class BeanDeserializer
/**
* If one of properties has "unwrapped" value, we need separate
* helper object
- *
- * @since 1.9
*/
protected UnwrappedPropertyHandler _unwrappedPropertyHandler;
@@ -199,11 +194,6 @@ public class BeanDeserializer
_property = property;
_valueInstantiator = valueInstantiator;
- if (valueInstantiator.canCreateFromObjectWith()) {
- _propertyBasedCreator = new PropertyBasedCreator(valueInstantiator);
- } else {
- _propertyBasedCreator = null;
- }
_beanProperties = properties;
_backRefs = backRefs;
@@ -213,10 +203,11 @@ public class BeanDeserializer
_injectables = (injectables == null || injectables.isEmpty()) ? null
: injectables.toArray(new ValueInjector[injectables.size()]);
- _nonStandardCreation = valueInstantiator.canCreateUsingDelegate()
- || (_propertyBasedCreator != null)
+ _nonStandardCreation = (_unwrappedPropertyHandler != null)
+ || valueInstantiator.canCreateUsingDelegate()
+ || valueInstantiator.canCreateFromObjectWith()
|| !valueInstantiator.canCreateUsingDefault()
- || (_unwrappedPropertyHandler != null);
+ ;
}
/**
@@ -280,8 +271,6 @@ public class BeanDeserializer
/**
* Accessor for checking number of deserialized properties.
- *
- * @since 1.7
*/
public int getPropertyCount() {
return _beanProperties.size();
@@ -291,13 +280,9 @@ public class BeanDeserializer
@Override public JavaType getValueType() { return _beanType; }
- /**
- *
- * @since 1.6
- */
public Iterator<SettableBeanProperty> properties()
{
- if (_beanProperties == null) { // since 1.7
+ if (_beanProperties == null) {
throw new IllegalStateException("Can only call before BeanDeserializer has been resolved");
}
return _beanProperties.allProperties();
@@ -315,9 +300,6 @@ public class BeanDeserializer
return _backRefs.get(logicalName);
}
- /**
- * @since 1.9
- */
public ValueInstantiator getValueInstantiator() {
return _valueInstantiator;
}
@@ -337,6 +319,18 @@ public class BeanDeserializer
public void resolve(DeserializationConfig config, DeserializerProvider provider)
throws JsonMappingException
{
+ // if ValueInstantiator can use "creator" approach, need to resolve it here...
+ if (_valueInstantiator.canCreateFromObjectWith()) {
+ SettableBeanProperty[] creatorProps = _valueInstantiator.getFromObjectArguments(config);
+ _propertyBasedCreator = new PropertyBasedCreator(_valueInstantiator, creatorProps);
+ for (SettableBeanProperty prop : creatorProps) {
+ if (!prop.hasValueDeserializer()) {
+ _propertyBasedCreator.assignDeserializer(prop,
+ findDeserializer(config, provider, prop.getType(), prop));
+ }
+ }
+ }
+
Iterator<SettableBeanProperty> it = _beanProperties.allProperties();
UnwrappedPropertyHandler unwrapped = null;
ExternalTypeHandler.Builder extTypes = null;
@@ -388,7 +382,7 @@ public class BeanDeserializer
// as well as delegate-based constructor:
if (_valueInstantiator.canCreateUsingDelegate()) {
- JavaType delegateType = _valueInstantiator.getDelegateType();
+ JavaType delegateType = _valueInstantiator.getDelegateType(config);
if (delegateType == null) {
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
@@ -400,16 +394,6 @@ public class BeanDeserializer
delegateType, _forClass.getAnnotations(), delegateCreator);
_delegateDeserializer = findDeserializer(config, provider, delegateType, property);
}
- // or property-based one
- // IMPORTANT: must access properties that _propertyBasedCreator has
- if (_propertyBasedCreator != null) {
- for (SettableBeanProperty prop : _propertyBasedCreator.getCreatorProperties()) {
- if (!prop.hasValueDeserializer()) {
- _propertyBasedCreator.assignDeserializer(prop,
- findDeserializer(config, provider, prop.getType(), prop));
- }
- }
- }
if (extTypes != null) {
_externalTypeIdHandler = extTypes.build();
// we consider this non-standard, to offline handling
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBuilder.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBuilder.java
index 52904d201..519dcbb62 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBuilder.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBuilder.java
@@ -33,16 +33,11 @@ public class BeanDeserializerBuilder
/**
* Properties to deserialize collected so far.
- *<p>
- * Note: since 1.9.1, LinkedHashMap has been used, since preservation
- * of order is actually important for some use cases.
*/
final protected HashMap<String, SettableBeanProperty> _properties = new LinkedHashMap<String, SettableBeanProperty>();
/**
* Value injectors for deserialization
- *
- * @since 1.9
*/
protected List<ValueInjector> _injectables;
@@ -59,8 +54,6 @@ public class BeanDeserializerBuilder
/**
* Object that will handle value instantiation for the bean type.
- *
- * @since 1.9
*/
protected ValueInstantiator _valueInstantiator;
@@ -91,8 +84,6 @@ public class BeanDeserializerBuilder
/**
* Copy constructor for sub-classes to use, when constructing
* custom builder instances
- *
- * @since 1.9
*/
protected BeanDeserializerBuilder(BeanDeserializerBuilder src)
{
@@ -192,8 +183,6 @@ public class BeanDeserializerBuilder
* decision if these properties need to be available through accessors.
* For now, however, we just have to ensure that we don't try to resolve
* types that masked setter/field has (see [JACKSON-700] for details).
- *
- * @since 1.9.2
*/
public void addCreatorProperty(BeanPropertyDefinition propDef)
{
@@ -212,9 +201,6 @@ public class BeanDeserializerBuilder
_ignoreAllUnknown = ignore;
}
- /**
- * @since 1.9
- */
public void setValueInstantiator(ValueInstantiator inst) {
_valueInstantiator = inst;
}
@@ -232,8 +218,6 @@ public class BeanDeserializerBuilder
* Note that properties are returned in order that properties
* are ordered (explictly, or by rule), which is the serialization
* order.
- *
- * @since 1.8.3
*/
public Iterator<SettableBeanProperty> getProperties() {
return _properties.values().iterator();
@@ -248,9 +232,6 @@ public class BeanDeserializerBuilder
return _properties.remove(name);
}
- /**
- * @since 1.9
- */
public ValueInstantiator getValueInstantiator() {
return _valueInstantiator;
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java
index 585bc121f..3249c5923 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java
@@ -1045,8 +1045,14 @@ public class BeanDeserializerFactory
for (String propName : ignored) {
builder.addIgnorable(propName);
}
+ // Also, do we have a fallback "any" setter?
+ AnnotatedMethod anySetter = beanDesc.findAnySetter();
+ if (anySetter != null) {
+ builder.setAnySetter(constructAnySetter(config, beanDesc, anySetter));
+ }
+ // NOTE: we do NOT add @JsonIgnore'd properties into blocked ones if there's any setter
// Implicit ones via @JsonIgnore and equivalent?
- {
+ if (anySetter == null) {
Collection<String> ignored2 = beanDesc.getIgnoredPropertyNames();
if (ignored2 != null) {
for (String propName : ignored2) {
@@ -1104,11 +1110,6 @@ public class BeanDeserializerFactory
}
}
}
- // Also, do we have a fallback "any" setter?
- AnnotatedMethod anySetter = beanDesc.findAnySetter();
- if (anySetter != null) {
- builder.setAnySetter(constructAnySetter(config, beanDesc, anySetter));
- }
/* As per [JACKSON-88], may also need to consider getters
* for Map/Collection properties
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/ValueInstantiator.java b/src/main/java/com/fasterxml/jackson/databind/deser/ValueInstantiator.java
index cc06099a2..344e781c9 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/ValueInstantiator.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/ValueInstantiator.java
@@ -3,6 +3,7 @@ package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.introspect.AnnotatedWithParams;
@@ -115,9 +116,8 @@ public abstract class ValueInstantiator
* constructor or factory method)
* is available for this instantiator
*/
- public boolean canCreateUsingDelegate() {
- return getDelegateType() != null;
- }
+ public abstract boolean canCreateUsingDelegate();
+// return getDelegateType(null) != null;
/**
* Method that can be called to check whether a property-based creator
@@ -138,7 +138,7 @@ public abstract class ValueInstantiator
* NOTE: all properties will be of type
* {@link com.fasterxml.jackson.databind.deser.impl.CreatorProperty}.
*/
- public SettableBeanProperty[] getFromObjectArguments() {
+ public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) {
return null;
}
@@ -149,7 +149,7 @@ public abstract class ValueInstantiator
* specified type (using standard deserializer for that type), and
* pass that to instantiator.
*/
- public JavaType getDelegateType() {
+ public JavaType getDelegateType(DeserializationConfig config) {
return null;
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyBasedCreator.java b/src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyBasedCreator.java
index e2967a8a2..f4b53e1ce 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyBasedCreator.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyBasedCreator.java
@@ -40,18 +40,16 @@ public final class PropertyBasedCreator
/**
* Array that contains properties that expect value to inject, if any;
* null if no injectable values are expected.
- *
- * @since 1.9
*/
protected final SettableBeanProperty[] _propertiesWithInjectables;
- public PropertyBasedCreator(ValueInstantiator valueInstantiator)
+ public PropertyBasedCreator(ValueInstantiator valueInstantiator,
+ SettableBeanProperty[] creatorProps)
{
_valueInstantiator = valueInstantiator;
_properties = new HashMap<String, SettableBeanProperty>();
// [JACKSON-372]: primitive types need extra care
Object[] defValues = null;
- SettableBeanProperty[] creatorProps = valueInstantiator.getFromObjectArguments();
SettableBeanProperty[] propertiesWithInjectables = null;
for (int i = 0, len = creatorProps.length; i < len; ++i) {
SettableBeanProperty prop = creatorProps[i];
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/CollectionDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/CollectionDeserializer.java
index 26d18e586..65b22c333 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/CollectionDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/CollectionDeserializer.java
@@ -100,7 +100,7 @@ public class CollectionDeserializer
{
// May need to resolve types for delegate-based creators:
if (_valueInstantiator.canCreateUsingDelegate()) {
- JavaType delegateType = _valueInstantiator.getDelegateType();
+ JavaType delegateType = _valueInstantiator.getDelegateType(config);
if (delegateType == null) {
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_collectionType
+": value instantiator ("+_valueInstantiator.getClass().getName()
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/JacksonDeserializers.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/JacksonDeserializers.java
index 0ea713872..64e793c80 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/JacksonDeserializers.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/JacksonDeserializers.java
@@ -2,6 +2,7 @@ package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
+import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
@@ -58,6 +59,21 @@ public class JacksonDeserializers
throw ctxt.mappingException(_valueClass);
}
}
+
+ @JacksonStdImpl
+ public static class JsonLocationDeserializer
+ extends StdScalarDeserializer<JsonLocation>
+ {
+ public JsonLocationDeserializer() { super(JsonLocation.class); }
+
+ @Override
+ public JsonLocation deserialize(JsonParser jp, DeserializationContext ctxt)
+ throws IOException, JsonProcessingException
+ {
+ // !!! TBI
+ return null;
+ }
+ }
/**
* We also want to directly support deserialization of {@link TokenBuffer}.
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java
index 39205c9a8..08ba614eb 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java
@@ -54,14 +54,8 @@ public class MapDeserializer
// // Instance construction settings:
- /**
- * @since 1.9
- */
protected final ValueInstantiator _valueInstantiator;
- /**
- * @since 1.9
- */
protected final boolean _hasDefaultCreator;
/**
@@ -98,11 +92,6 @@ public class MapDeserializer
_valueDeserializer = valueDeser;
_valueTypeDeserializer = valueTypeDeser;
_valueInstantiator = valueInstantiator;
- if (valueInstantiator.canCreateFromObjectWith()) {
- _propertyBasedCreator = new PropertyBasedCreator(valueInstantiator);
- } else {
- _propertyBasedCreator = null;
- }
_hasDefaultCreator = valueInstantiator.canCreateUsingDefault();
}
@@ -148,7 +137,7 @@ public class MapDeserializer
{
// May need to resolve types for delegate- and/or property-based creators:
if (_valueInstantiator.canCreateUsingDelegate()) {
- JavaType delegateType = _valueInstantiator.getDelegateType();
+ JavaType delegateType = _valueInstantiator.getDelegateType(config);
if (delegateType == null) {
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_mapType
+": value instantiator ("+_valueInstantiator.getClass().getName()
@@ -161,8 +150,10 @@ public class MapDeserializer
delegateType, null, delegateCreator);
_delegateDeserializer = findDeserializer(config, provider, delegateType, property);
}
- if (_propertyBasedCreator != null) {
- for (SettableBeanProperty prop : _propertyBasedCreator.getCreatorProperties()) {
+ if (_valueInstantiator.canCreateFromObjectWith()) {
+ SettableBeanProperty[] creatorProps = _valueInstantiator.getFromObjectArguments(config);
+ _propertyBasedCreator = new PropertyBasedCreator(_valueInstantiator, creatorProps);
+ for (SettableBeanProperty prop : creatorProps) {
if (!prop.hasValueDeserializer()) {
_propertyBasedCreator.assignDeserializer(prop, findDeserializer(config, provider, prop.getType(), prop));
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java
index 338f314eb..9ce1d7726 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java
@@ -17,8 +17,6 @@ import com.fasterxml.jackson.databind.introspect.AnnotatedWithParams;
* supports use of default constructor. Sub-types can add
* support for alternate construction methods, such as using
* argument-taking constructors or static factory methods.
- *
- * @since 1.9.0
*/
public class StdValueInstantiator
extends ValueInstantiator
@@ -182,17 +180,22 @@ public class StdValueInstantiator
}
@Override
+ public boolean canCreateUsingDelegate() {
+ return _delegateType != null;
+ }
+
+ @Override
public boolean canCreateFromObjectWith() {
return (_withArgsCreator != null);
}
@Override
- public JavaType getDelegateType() {
+ public JavaType getDelegateType(DeserializationConfig config) {
return _delegateType;
}
@Override
- public SettableBeanProperty[] getFromObjectArguments() {
+ public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) {
return _constructorArguments;
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringCollectionDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringCollectionDeserializer.java
index e3b3396ae..e0a61b2e5 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringCollectionDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringCollectionDeserializer.java
@@ -101,7 +101,7 @@ public final class StringCollectionDeserializer
// May need to resolve types for delegate-based creators:
AnnotatedWithParams delegateCreator = _valueInstantiator.getDelegateCreator();
if (delegateCreator != null) {
- JavaType delegateType = _valueInstantiator.getDelegateType();
+ JavaType delegateType = _valueInstantiator.getDelegateType(config);
// Need to create a temporary property to allow contextual deserializers:
BeanProperty.Std property = new BeanProperty.Std(null,
delegateType, null, delegateCreator);