Package org.codehaus.jackson.map.deser
Class ValueInstantiator
- java.lang.Object
-
- org.codehaus.jackson.map.deser.ValueInstantiator
-
- Direct Known Subclasses:
StdValueInstantiator
public abstract class ValueInstantiator extends java.lang.Object
Class that defines simple API implemented by objects that create value instances. Some or all of properties of value instances may be initialized by instantiator, rest being populated by deserializer, to which value instance is passed. Since different kinds of JSON values (structured and scalar) may be bound to Java values, in some cases instantiator fully defines resulting value; this is the case when JSON value is a scalar value (String, number, boolean).Note that this type is not parameterized (even though it would seemingly make sense), because such type information can not be use effectively during runtime: access is always using either wildcard type, or just basic
Object
; and so adding type parameter seems like unnecessary extra work.Actual implementations are strongly recommended to be based on
StdValueInstantiator
which implements all methods, and as such will be compatible across versions even if new methods were added to this interface.- Since:
- 1.9
-
-
Constructor Summary
Constructors Constructor Description ValueInstantiator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
canCreateFromBoolean()
Method that can be called to check whether a double (boolean / Boolean) based creator is available to use (to callcreateFromDouble(double)
).boolean
canCreateFromDouble()
Method that can be called to check whether a double (double / Double) based creator is available to use (to callcreateFromDouble(double)
).boolean
canCreateFromInt()
Method that can be called to check whether an integer (int, Integer) based creator is available to use (to callcreateFromInt(int)
).boolean
canCreateFromLong()
Method that can be called to check whether a long (long, Long) based creator is available to use (to callcreateFromLong(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 instantiatorboolean
canCreateUsingDelegate()
Method that can be called to check whether a delegate-based creator (single-arg constructor or factory method) is available for this instantiatorboolean
canInstantiate()
Method that will return true if any ofcanCreateXxx
method returns true: that is, if there is any way that an instance could be created.java.lang.Object
createFromBoolean(boolean value)
java.lang.Object
createFromDouble(double value)
java.lang.Object
createFromInt(int value)
java.lang.Object
createFromLong(long value)
java.lang.Object
createFromObjectWith(java.lang.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.java.lang.Object
createFromString(java.lang.String value)
java.lang.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.java.lang.Object
createUsingDelegate(java.lang.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 (whencanCreateFromObjectWith()
returns true).abstract java.lang.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).
-
-
-
Method Detail
-
getValueTypeDesc
public abstract java.lang.String getValueTypeDesc()
Method that returns description of the value type this instantiator handles. Used for error messages, diagnostics.
-
canInstantiate
public boolean canInstantiate()
Method that will return true if any ofcanCreateXxx
method returns true: that is, if there is any way that an instance could be created.
-
canCreateFromString
public boolean canCreateFromString()
Method that can be called to check whether a String-based creator is available for this instantiator
-
canCreateFromInt
public boolean canCreateFromInt()
Method that can be called to check whether an integer (int, Integer) based creator is available to use (to callcreateFromInt(int)
).
-
canCreateFromLong
public boolean canCreateFromLong()
Method that can be called to check whether a long (long, Long) based creator is available to use (to callcreateFromLong(long)
).
-
canCreateFromDouble
public boolean canCreateFromDouble()
Method that can be called to check whether a double (double / Double) based creator is available to use (to callcreateFromDouble(double)
).
-
canCreateFromBoolean
public boolean canCreateFromBoolean()
Method that can be called to check whether a double (boolean / Boolean) based creator is available to use (to callcreateFromDouble(double)
).
-
canCreateUsingDefault
public boolean canCreateUsingDefault()
Method that can be called to check whether a default creator (constructor, or no-arg static factory method) is available for this instantiator
-
canCreateUsingDelegate
public boolean canCreateUsingDelegate()
Method that can be called to check whether a delegate-based creator (single-arg constructor or factory method) is available for this instantiator
-
canCreateFromObjectWith
public 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 Object
-
getFromObjectArguments
public SettableBeanProperty[] getFromObjectArguments()
Method called to determine types of instantiation arguments to use when creating instances with creator arguments (whencanCreateFromObjectWith()
returns true). These arguments are bound from JSON, using specified property types to locate deserializers.NOTE: all properties will be of type
CreatorProperty
.
-
getDelegateType
public 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. If non-null type is returned, deserializer will bind JSON into specified type (using standard deserializer for that type), and pass that to instantiator.
-
createUsingDefault
public java.lang.Object createUsingDefault() throws java.io.IOException, JsonProcessingException
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
getFromObjectArguments()
returns null or empty List.- Throws:
java.io.IOException
JsonProcessingException
-
createFromObjectWith
public java.lang.Object createFromObjectWith(java.lang.Object[] args) throws java.io.IOException, JsonProcessingException
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
getFromObjectArguments()
returns a non-empty List of arguments.- Throws:
java.io.IOException
JsonProcessingException
-
createUsingDelegate
public java.lang.Object createUsingDelegate(java.lang.Object delegate) throws java.io.IOException, JsonProcessingException
Method to called to create value instance from JSON Object using an intermediate "delegate" value to pass to createor method- Throws:
java.io.IOException
JsonProcessingException
-
createFromString
public java.lang.Object createFromString(java.lang.String value) throws java.io.IOException, JsonProcessingException
- Throws:
java.io.IOException
JsonProcessingException
-
createFromInt
public java.lang.Object createFromInt(int value) throws java.io.IOException, JsonProcessingException
- Throws:
java.io.IOException
JsonProcessingException
-
createFromLong
public java.lang.Object createFromLong(long value) throws java.io.IOException, JsonProcessingException
- Throws:
java.io.IOException
JsonProcessingException
-
createFromDouble
public java.lang.Object createFromDouble(double value) throws java.io.IOException, JsonProcessingException
- Throws:
java.io.IOException
JsonProcessingException
-
createFromBoolean
public java.lang.Object createFromBoolean(boolean value) throws java.io.IOException, JsonProcessingException
- Throws:
java.io.IOException
JsonProcessingException
-
getDefaultCreator
public AnnotatedWithParams 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). Note that implementations not required to return actual object they use (or, they may use some other instantiation) method. That is, even ifcanCreateUsingDefault()
returns true, this method may return null .
-
getDelegateCreator
public AnnotatedWithParams getDelegateCreator()
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 ifcanCreateUsingDelegate()
returns true, this method may return null .
-
getWithArgsCreator
public 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). Note that implementations not required to return actual object they use (or, they may use some other instantiation) method. That is, even ifcanCreateFromObjectWith()
returns true, this method may return null .
-
-