com.fasterxml.jackson.databind.cfg

## Class ConstructorDetector

- java.lang.Object
- - com.fasterxml.jackson.databind.cfg.ConstructorDetector

- All Implemented Interfaces:
    Serializable

      public final class ConstructorDetector
      extends Object
      implements Serializable

  Configurable handler used to select aspects of selecting constructor to use as "Creator" for POJOs. Defines the API for handlers, a pre-defined set of standard instances and methods for constructing alternative configurations.
  Since:
    2.12
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ConstructorDetector.SingleArgConstructor` Definition of alternate handling modes of single-argument constructors that are annotated with `JsonCreator` but without "mode" definition (or explicit name for the argument): this is the case where two interpretations are possible -- "properties" (in which case the argument is named parameter of a JSON Object) and "delegating (in which case the argument maps to the whole JSON value).

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `_allowJDKTypeCtors` Whether auto-detection of constructors of "JDK types" (those in packages `java.` and `javax.`) is allowed or not
    `protected boolean` | `_requireCtorAnnotation` Whether explicit `JsonCreator` is always required for detecting constructors (even if visible) other than the default (no argument) constructor.
    `protected ConstructorDetector.SingleArgConstructor` | `_singleArgMode`
    `static ConstructorDetector` | `DEFAULT` Instance used by default, which: Uses `ConstructorDetector.SingleArgConstructor.HEURISTIC` for single-argument constructor case Does not require explicit `@JsonCreator` annotations (so allows auto-detection of Visible constructors} (except for JDK types) Does not allow auto-detection of Visible constructors for so-called JDK types; that is, classes in packages `java.*` and `javax.*`
    `static ConstructorDetector` | `EXPLICIT_ONLY` Instance similar to `DEFAULT` except that for single-argument case uses setting of `ConstructorDetector.SingleArgConstructor.REQUIRE_MODE`.
    `static ConstructorDetector` | `USE_DELEGATING` Instance similar to `DEFAULT` except that for single-argument case uses setting of `ConstructorDetector.SingleArgConstructor.DELEGATING`.
    `static ConstructorDetector` | `USE_PROPERTIES_BASED` Instance similar to `DEFAULT` except that for single-argument case uses setting of `ConstructorDetector.SingleArgConstructor.PROPERTIES`.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ConstructorDetector(ConstructorDetector.SingleArgConstructor singleArgMode)` Constructors used for default configurations which only varies by `_singleArgMode`
    `protected` | `ConstructorDetector(ConstructorDetector.SingleArgConstructor singleArgMode, boolean requireCtorAnnotation, boolean allowJDKTypeCtors)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `allowJDKTypeConstructors()`
    `boolean` | `requireCtorAnnotation()`
    `boolean` | `shouldIntrospectorImplicitConstructors(Class<?> rawType)` Accessor that combines checks for whether implicit creators are allowed and, if so, whether JDK type constructors are allowed (if type is JDK type) to determine whether implicit constructor detection should be enabled for given type or not.
    `boolean` | `singleArgCreatorDefaultsToDelegating()`
    `boolean` | `singleArgCreatorDefaultsToProperties()`
    `ConstructorDetector.SingleArgConstructor` | `singleArgMode()`
    `ConstructorDetector` | `withAllowJDKTypeConstructors(boolean state)`
    `ConstructorDetector` | `withRequireAnnotation(boolean state)`
    `ConstructorDetector` | `withSingleArgMode(ConstructorDetector.SingleArgConstructor singleArgMode)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT

          public static final ConstructorDetector DEFAULT

      Instance used by default, which:
      - Uses `ConstructorDetector.SingleArgConstructor.HEURISTIC` for single-argument constructor case
      - Does not require explicit `@JsonCreator` annotations (so allows auto-detection of Visible constructors} (except for JDK types)
      - Does not allow auto-detection of Visible constructors for so-called JDK types; that is, classes in packages `java.*` and `javax.*`

    - #### USE_PROPERTIES_BASED

          public static final ConstructorDetector USE_PROPERTIES_BASED

      Instance similar to `DEFAULT` except that for single-argument case uses setting of `ConstructorDetector.SingleArgConstructor.PROPERTIES`.

    - #### USE_DELEGATING

          public static final ConstructorDetector USE_DELEGATING

      Instance similar to `DEFAULT` except that for single-argument case uses setting of `ConstructorDetector.SingleArgConstructor.DELEGATING`.

    - #### EXPLICIT_ONLY

          public static final ConstructorDetector EXPLICIT_ONLY

      Instance similar to `DEFAULT` except that for single-argument case uses setting of `ConstructorDetector.SingleArgConstructor.REQUIRE_MODE`.

    - #### _singleArgMode

          protected final ConstructorDetector.SingleArgConstructor _singleArgMode

    - #### _requireCtorAnnotation

          protected final boolean _requireCtorAnnotation

      Whether explicit `JsonCreator` is always required for detecting constructors (even if visible) other than the default (no argument) constructor.

    - #### _allowJDKTypeCtors

          protected final boolean _allowJDKTypeCtors

      Whether auto-detection of constructors of "JDK types" (those in packages `java.` and `javax.`) is allowed or not

  - ### Constructor Detail

    - #### ConstructorDetector

          protected ConstructorDetector(ConstructorDetector.SingleArgConstructor singleArgMode,
                                        boolean requireCtorAnnotation,
                                        boolean allowJDKTypeCtors)

    - #### ConstructorDetector

          protected ConstructorDetector(ConstructorDetector.SingleArgConstructor singleArgMode)

      Constructors used for default configurations which only varies by `_singleArgMode`

  - ### Method Detail

    - #### withSingleArgMode

          public ConstructorDetector withSingleArgMode(ConstructorDetector.SingleArgConstructor singleArgMode)

    - #### withRequireAnnotation

          public ConstructorDetector withRequireAnnotation(boolean state)

    - #### withAllowJDKTypeConstructors

          public ConstructorDetector withAllowJDKTypeConstructors(boolean state)

    - #### singleArgMode

          public ConstructorDetector.SingleArgConstructor singleArgMode()

    - #### requireCtorAnnotation

          public boolean requireCtorAnnotation()

    - #### allowJDKTypeConstructors

          public boolean allowJDKTypeConstructors()

    - #### singleArgCreatorDefaultsToDelegating

          public boolean singleArgCreatorDefaultsToDelegating()

    - #### singleArgCreatorDefaultsToProperties

          public boolean singleArgCreatorDefaultsToProperties()

    - #### shouldIntrospectorImplicitConstructors

          public boolean shouldIntrospectorImplicitConstructors(Class<?> rawType)

      Accessor that combines checks for whether implicit creators are allowed and, if so, whether JDK type constructors are allowed (if type is JDK type) to determine whether implicit constructor detection should be enabled for given type or not.
      Parameters:
        `rawType` - Value type to consider
      Returns:
        True if implicit constructor detection should be enabled; false if not

Copyright © 2008–2020 FasterXML. All rights reserved.