Class StdValueInstantiator
- java.lang.Object
-
- org.codehaus.jackson.map.deser.ValueInstantiator
-
- org.codehaus.jackson.map.deser.std.StdValueInstantiator
-
public class StdValueInstantiator extends ValueInstantiator
BasicValueInstantiator
implementation, which only 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
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_cfgEmptyStringsAsObjects
Are we allowed to convert empty Strings to null objects?protected CreatorProperty[]
_constructorArguments
protected AnnotatedWithParams
_defaultCreator
Default (no-argument) constructor to use for instantiation (withcreateUsingDefault()
)protected AnnotatedWithParams
_delegateCreator
protected JavaType
_delegateType
protected AnnotatedWithParams
_fromBooleanCreator
protected AnnotatedWithParams
_fromDoubleCreator
protected AnnotatedWithParams
_fromIntCreator
protected AnnotatedWithParams
_fromLongCreator
protected AnnotatedWithParams
_fromStringCreator
protected String
_valueTypeDesc
Type of values that are instantiated; used for error reporting purposes.protected AnnotatedWithParams
_withArgsCreator
-
Constructor Summary
Constructors Modifier Constructor Description protected
StdValueInstantiator(StdValueInstantiator src)
Copy-constructor that sub-classes can use when creating new instances by fluent-style constructionStdValueInstantiator(DeserializationConfig config, Class<?> valueType)
StdValueInstantiator(DeserializationConfig config, JavaType valueType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
_createFromStringFallbacks(String value)
boolean
canCreateFromBoolean()
Method that can be called to check whether a double (boolean / Boolean) based creator is available to use (to callValueInstantiator.createFromDouble(double)
).boolean
canCreateFromDouble()
Method that can be called to check whether a double (double / Double) based creator is available to use (to callValueInstantiator.createFromDouble(double)
).boolean
canCreateFromInt()
Method that can be called to check whether an integer (int, Integer) based creator is available to use (to callValueInstantiator.createFromInt(int)
).boolean
canCreateFromLong()
Method that can be called to check whether a long (long, Long) based creator is available to use (to callValueInstantiator.createFromLong(long)
).boolean
canCreateFromObjectWith()
Method that can be called to check whether a property-based creator (argument-taking constructor or factory method) is available to instantiate values from JSON Objectboolean
canCreateFromString()
Method that can be called to check whether a String-based creator is available for this instantiatorboolean
canCreateUsingDefault()
Method that can be called to check whether a default creator (constructor, or no-arg static factory method) is available for this instantiatorvoid
configureFromBooleanCreator(AnnotatedWithParams creator)
void
configureFromDoubleCreator(AnnotatedWithParams creator)
void
configureFromIntCreator(AnnotatedWithParams creator)
void
configureFromLongCreator(AnnotatedWithParams creator)
void
configureFromObjectSettings(AnnotatedWithParams defaultCreator, AnnotatedWithParams delegateCreator, JavaType delegateType, AnnotatedWithParams withArgsCreator, CreatorProperty[] constructorArgs)
Method for setting properties related to instantiating values from JSON Object.void
configureFromStringCreator(AnnotatedWithParams creator)
Object
createFromBoolean(boolean value)
Object
createFromDouble(double value)
Object
createFromInt(int value)
Object
createFromLong(long value)
Object
createFromObjectWith(Object[] args)
Method called to create value instance from JSON Object when instantiation arguments are passed; this is done, for example when passing information specified with "Creator" annotations.Object
createFromString(String value)
Object
createUsingDefault()
Method called to create value instance from a JSON value when no data needs to passed to creator (constructor, factory method); typically this will call the default constructor of the value object.Object
createUsingDelegate(Object delegate)
Method to called to create value instance from JSON Object using an intermediate "delegate" value to pass to createor methodAnnotatedWithParams
getDefaultCreator()
Method that can be called to try to access member (constructor, static factory method) that is used as the "default creator" (creator that is called without arguments; typically default [zero-argument] constructor of the type).AnnotatedWithParams
getDelegateCreator()
Method that can be called to try to access member (constructor, static factory method) that is used as the "delegate creator".JavaType
getDelegateType()
Method that can be used to determine what is the type of delegate type to use, if any; if no delegates are used, will return null.SettableBeanProperty[]
getFromObjectArguments()
Method called to determine types of instantiation arguments to use when creating instances with creator arguments (whenValueInstantiator.canCreateFromObjectWith()
returns true).String
getValueTypeDesc()
Method that returns description of the value type this instantiator handles.AnnotatedWithParams
getWithArgsCreator()
Method that can be called to try to access member (constructor, static factory method) that is used as the "non-default creator" (constructor or factory method that takes one or more arguments).protected JsonMappingException
wrapException(Throwable t)
-
Methods inherited from class org.codehaus.jackson.map.deser.ValueInstantiator
canCreateUsingDelegate, canInstantiate
-
-
-
-
Field Detail
-
_valueTypeDesc
protected final String _valueTypeDesc
Type of values that are instantiated; used for error reporting purposes.
-
_cfgEmptyStringsAsObjects
protected final boolean _cfgEmptyStringsAsObjects
Are we allowed to convert empty Strings to null objects?
-
_defaultCreator
protected AnnotatedWithParams _defaultCreator
Default (no-argument) constructor to use for instantiation (withcreateUsingDefault()
)
-
_constructorArguments
protected CreatorProperty[] _constructorArguments
-
_withArgsCreator
protected AnnotatedWithParams _withArgsCreator
-
_delegateType
protected JavaType _delegateType
-
_delegateCreator
protected AnnotatedWithParams _delegateCreator
-
_fromStringCreator
protected AnnotatedWithParams _fromStringCreator
-
_fromIntCreator
protected AnnotatedWithParams _fromIntCreator
-
_fromLongCreator
protected AnnotatedWithParams _fromLongCreator
-
_fromDoubleCreator
protected AnnotatedWithParams _fromDoubleCreator
-
_fromBooleanCreator
protected AnnotatedWithParams _fromBooleanCreator
-
-
Constructor Detail
-
StdValueInstantiator
public StdValueInstantiator(DeserializationConfig config, Class<?> valueType)
-
StdValueInstantiator
public StdValueInstantiator(DeserializationConfig config, JavaType valueType)
-
StdValueInstantiator
protected StdValueInstantiator(StdValueInstantiator src)
Copy-constructor that sub-classes can use when creating new instances by fluent-style construction
-
-
Method Detail
-
configureFromObjectSettings
public void configureFromObjectSettings(AnnotatedWithParams defaultCreator, AnnotatedWithParams delegateCreator, JavaType delegateType, AnnotatedWithParams withArgsCreator, CreatorProperty[] constructorArgs)
Method for setting properties related to instantiating values from JSON Object. We will choose basically only one approach (out of possible three), and clear other properties
-
configureFromStringCreator
public void configureFromStringCreator(AnnotatedWithParams creator)
-
configureFromIntCreator
public void configureFromIntCreator(AnnotatedWithParams creator)
-
configureFromLongCreator
public void configureFromLongCreator(AnnotatedWithParams creator)
-
configureFromDoubleCreator
public void configureFromDoubleCreator(AnnotatedWithParams creator)
-
configureFromBooleanCreator
public void configureFromBooleanCreator(AnnotatedWithParams creator)
-
getValueTypeDesc
public String getValueTypeDesc()
Description copied from class:ValueInstantiator
Method that returns description of the value type this instantiator handles. Used for error messages, diagnostics.- Specified by:
getValueTypeDesc
in classValueInstantiator
-
canCreateFromString
public boolean canCreateFromString()
Description copied from class:ValueInstantiator
Method that can be called to check whether a String-based creator is available for this instantiator- Overrides:
canCreateFromString
in classValueInstantiator
-
canCreateFromInt
public boolean canCreateFromInt()
Description copied from class:ValueInstantiator
Method that can be called to check whether an integer (int, Integer) based creator is available to use (to callValueInstantiator.createFromInt(int)
).- Overrides:
canCreateFromInt
in classValueInstantiator
-
canCreateFromLong
public boolean canCreateFromLong()
Description copied from class:ValueInstantiator
Method that can be called to check whether a long (long, Long) based creator is available to use (to callValueInstantiator.createFromLong(long)
).- Overrides:
canCreateFromLong
in classValueInstantiator
-
canCreateFromDouble
public boolean canCreateFromDouble()
Description copied from class:ValueInstantiator
Method that can be called to check whether a double (double / Double) based creator is available to use (to callValueInstantiator.createFromDouble(double)
).- Overrides:
canCreateFromDouble
in classValueInstantiator
-
canCreateFromBoolean
public boolean canCreateFromBoolean()
Description copied from class:ValueInstantiator
Method that can be called to check whether a double (boolean / Boolean) based creator is available to use (to callValueInstantiator.createFromDouble(double)
).- Overrides:
canCreateFromBoolean
in classValueInstantiator
-
canCreateUsingDefault
public boolean canCreateUsingDefault()
Description copied from class:ValueInstantiator
Method that can be called to check whether a default creator (constructor, or no-arg static factory method) is available for this instantiator- Overrides:
canCreateUsingDefault
in classValueInstantiator
-
canCreateFromObjectWith
public boolean canCreateFromObjectWith()
Description copied from class:ValueInstantiator
Method that can be called to check whether a property-based creator (argument-taking constructor or factory method) is available to instantiate values from JSON Object- Overrides:
canCreateFromObjectWith
in classValueInstantiator
-
getDelegateType
public JavaType getDelegateType()
Description copied from class:ValueInstantiator
Method that can be used to determine what is the type of delegate type to use, if any; if no delegates are used, will return null. If non-null type is returned, deserializer will bind JSON into specified type (using standard deserializer for that type), and pass that to instantiator.- Overrides:
getDelegateType
in classValueInstantiator
-
getFromObjectArguments
public SettableBeanProperty[] getFromObjectArguments()
Description copied from class:ValueInstantiator
Method called to determine types of instantiation arguments to use when creating instances with creator arguments (whenValueInstantiator.canCreateFromObjectWith()
returns true). These arguments are bound from JSON, using specified property types to locate deserializers.NOTE: all properties will be of type
CreatorProperty
.- Overrides:
getFromObjectArguments
in classValueInstantiator
-
createUsingDefault
public Object createUsingDefault() throws IOException, JsonProcessingException
Description copied from class:ValueInstantiator
Method called to create value instance from a JSON value when no data needs to passed to creator (constructor, factory method); typically this will call the default constructor of the value object. It will only be used if more specific creator methods are not applicable; hence "default".This method is called if
ValueInstantiator.getFromObjectArguments()
returns null or empty List.- Overrides:
createUsingDefault
in classValueInstantiator
- Throws:
IOException
JsonProcessingException
-
createFromObjectWith
public Object createFromObjectWith(Object[] args) throws IOException, JsonProcessingException
Description copied from class:ValueInstantiator
Method called to create value instance from JSON Object when instantiation arguments are passed; this is done, for example when passing information specified with "Creator" annotations.This method is called if
ValueInstantiator.getFromObjectArguments()
returns a non-empty List of arguments.- Overrides:
createFromObjectWith
in classValueInstantiator
- Throws:
IOException
JsonProcessingException
-
createUsingDelegate
public Object createUsingDelegate(Object delegate) throws IOException, JsonProcessingException
Description copied from class:ValueInstantiator
Method to called to create value instance from JSON Object using an intermediate "delegate" value to pass to createor method- Overrides:
createUsingDelegate
in classValueInstantiator
- Throws:
IOException
JsonProcessingException
-
createFromString
public Object createFromString(String value) throws IOException, JsonProcessingException
- Overrides:
createFromString
in classValueInstantiator
- Throws:
IOException
JsonProcessingException
-
createFromInt
public Object createFromInt(int value) throws IOException, JsonProcessingException
- Overrides:
createFromInt
in classValueInstantiator
- Throws:
IOException
JsonProcessingException
-
createFromLong
public Object createFromLong(long value) throws IOException, JsonProcessingException
- Overrides:
createFromLong
in classValueInstantiator
- Throws:
IOException
JsonProcessingException
-
createFromDouble
public Object createFromDouble(double value) throws IOException, JsonProcessingException
- Overrides:
createFromDouble
in classValueInstantiator
- Throws:
IOException
JsonProcessingException
-
createFromBoolean
public Object createFromBoolean(boolean value) throws IOException, JsonProcessingException
- Overrides:
createFromBoolean
in classValueInstantiator
- Throws:
IOException
JsonProcessingException
-
getDelegateCreator
public AnnotatedWithParams getDelegateCreator()
Description copied from class:ValueInstantiator
Method that can be called to try to access member (constructor, static factory method) that is used as the "delegate creator". Note that implementations not required to return actual object they use (or, they may use some other instantiation) method. That is, even ifValueInstantiator.canCreateUsingDelegate()
returns true, this method may return null .- Overrides:
getDelegateCreator
in classValueInstantiator
-
getDefaultCreator
public AnnotatedWithParams getDefaultCreator()
Description copied from class:ValueInstantiator
Method that can be called to try to access member (constructor, static factory method) that is used as the "default creator" (creator that is called without arguments; typically default [zero-argument] constructor of the type). Note that implementations not required to return actual object they use (or, they may use some other instantiation) method. That is, even ifValueInstantiator.canCreateUsingDefault()
returns true, this method may return null .- Overrides:
getDefaultCreator
in classValueInstantiator
-
getWithArgsCreator
public AnnotatedWithParams getWithArgsCreator()
Description copied from class:ValueInstantiator
Method that can be called to try to access member (constructor, static factory method) that is used as the "non-default creator" (constructor or factory method that takes one or more arguments). Note that implementations not required to return actual object they use (or, they may use some other instantiation) method. That is, even ifValueInstantiator.canCreateFromObjectWith()
returns true, this method may return null .- Overrides:
getWithArgsCreator
in classValueInstantiator
-
_createFromStringFallbacks
protected Object _createFromStringFallbacks(String value) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
wrapException
protected JsonMappingException wrapException(Throwable t)
-
-