Class ValueInstantiator

  • Direct Known Subclasses:
    StdValueInstantiator, ValueInstantiator.Base, ValueInstantiator.Delegating

    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 cannot 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.

    • Constructor Detail

      • ValueInstantiator

        public ValueInstantiator()
    • Method Detail

      • createContextual

        public ValueInstantiator createContextual​(DeserializationContext ctxt,
                                                  BeanDescription beanDesc)
                                           throws JsonMappingException
        "Contextualization" method that is called after construction but before first use, to allow instantiator access to context needed to possible resolve its dependencies.
        Parameters:
        ctxt - Currently active deserialization context: needed to (for example) resolving TypeDeserializers.
        Returns:
        This instance, if no change, or newly constructed instance
        Throws:
        JsonMappingException - If there are issues with contextualization
        Since:
        2.12
      • getValueClass

        public java.lang.Class<?> getValueClass()
        Accessor for raw (type-erased) type of instances to create.

        NOTE: since this method has not existed since beginning of Jackson 2.0 series, default implementation will just return Object.class; implementations are expected to override it with real value.

        Since:
        2.8
      • getValueTypeDesc

        public 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 of canCreateXxx 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.

        NOTE: does NOT include possible case of fallbacks, or coercion; only considers explicit creator.

      • 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
      • canCreateUsingArrayDelegate

        public boolean canCreateUsingArrayDelegate()
        Method that can be called to check whether a array-delegate-based creator (single-arg constructor or factory method) is available for this instantiator
        Since:
        2.7
      • 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​(DeserializationConfig config)
        Method called to determine types of instantiation arguments to use when creating instances with creator arguments (when canCreateFromObjectWith() 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​(DeserializationConfig config)
        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.
      • getArrayDelegateType

        public JavaType getArrayDelegateType​(DeserializationConfig config)
        Method that can be used to determine what is the type of array 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.
        Since:
        2.7
      • createUsingDefault

        public java.lang.Object createUsingDefault​(DeserializationContext ctxt)
                                            throws java.io.IOException
        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(com.fasterxml.jackson.databind.DeserializationConfig) returns null or empty List.

        Throws:
        java.io.IOException
      • createFromObjectWith

        public java.lang.Object createFromObjectWith​(DeserializationContext ctxt,
                                                     java.lang.Object[] args)
                                              throws java.io.IOException
        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(com.fasterxml.jackson.databind.DeserializationConfig) returns a non-empty List of arguments.

        Throws:
        java.io.IOException
      • createUsingDelegate

        public java.lang.Object createUsingDelegate​(DeserializationContext ctxt,
                                                    java.lang.Object delegate)
                                             throws java.io.IOException
        Method to called to create value instance from JSON Object using an intermediate "delegate" value to pass to createor method
        Throws:
        java.io.IOException
      • createUsingArrayDelegate

        public java.lang.Object createUsingArrayDelegate​(DeserializationContext ctxt,
                                                         java.lang.Object delegate)
                                                  throws java.io.IOException
        Method to called to create value instance from JSON Array using an intermediate "delegate" value to pass to createor method
        Throws:
        java.io.IOException
      • createFromString

        public java.lang.Object createFromString​(DeserializationContext ctxt,
                                                 java.lang.String value)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • createFromInt

        public java.lang.Object createFromInt​(DeserializationContext ctxt,
                                              int value)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • createFromLong

        public java.lang.Object createFromLong​(DeserializationContext ctxt,
                                               long value)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • createFromBigInteger

        public java.lang.Object createFromBigInteger​(DeserializationContext ctxt,
                                                     java.math.BigInteger value)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • createFromDouble

        public java.lang.Object createFromDouble​(DeserializationContext ctxt,
                                                 double value)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • createFromBigDecimal

        public java.lang.Object createFromBigDecimal​(DeserializationContext ctxt,
                                                     java.math.BigDecimal value)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • createFromBoolean

        public java.lang.Object createFromBoolean​(DeserializationContext ctxt,
                                                  boolean value)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • 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 if canCreateUsingDefault() 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 if canCreateUsingDelegate() returns true, this method may return null .
      • getArrayDelegateCreator

        public AnnotatedWithParams getArrayDelegateCreator()
        Method that can be called to try to access member (constructor, static factory method) that is used as the "array delegate creator". Note that implementations not required to return actual object they use (or, they may use some other instantiation) method. That is, even if canCreateUsingArrayDelegate() 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 if canCreateFromObjectWith() returns true, this method may return null .