Top Description Inners Methods
com.fasterxml.jackson.annotation

public @Interface JsonCreator

extends Annotation
Annotations
@Target:ANNOTATION_TYPE, METHOD, CONSTRUCTOR
@Retention:RUNTIME
@JacksonAnnotation
Imports
java.lang.annotation.ElementType, .Retention, .RetentionPolicy, .Target

Marker annotation that can be used to define constructors and factory methods as one to use for instantiating new instances of the associated class.

NOTE: when annotating creator methods (constructors, factory methods), method must either be:

Also note that all JsonProperty annotations must specify actual name (NOT empty String for "default") unless you use one of extension modules that can detect parameter name; this because default JDK versions before 8 have not been able to store and/or retrieve parameter names from bytecode. But with JDK 8 (or using helper libraries such as Paranamer, or other JVM languages like Scala or Kotlin), specifying name is optional.

One common use case is to use a delegating Creator to construct instances from scalar values (like java.lang.String) during deserialization, and serialize values using JsonValue.

Note

As of Jackson 2.6, use of JsonProperty#required() is supported for Creator methods (but not necessarily for regular setters or fields!).

See Also
JsonProperty

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Method Summary

Modifier and TypeMethod and Description
public JsonCreator.Mode
mode()

Property that is used to indicate how argument(s) is/are bound for creator, in cases there may be multiple alternatives.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

modeback to summary
public JsonCreator.Mode mode()

Property that is used to indicate how argument(s) is/are bound for creator, in cases there may be multiple alternatives. Currently the one case is that of a single-argument creator method, for which both so-called "delegating" and "property-based" bindings are possible: since delegating mode can not be used for multi-argument creators, the only choice there is "property-based" mode. Check Mode for more complete explanation of possible choices.

Default value of Mode#DEFAULT means that caller is to use standard heuristics for choosing mode to use.

Since
2.5
com.fasterxml.jackson.annotation back to summary

public final Enum JsonCreator.Mode

extends Enum<JsonCreator.Mode>
Class Inheritance

Since
2.5

Field Summary

Modifier and TypeField and Description
public static final JsonCreator.Mode
DEFAULT

Pseudo-mode that indicates that caller is to use default heuristics for choosing mode to use.

public static final JsonCreator.Mode
DELEGATING

Mode that indicates that if creator takes a single argument, the whole incoming data value is to be bound into declared type of that argument; this "delegate" value is then passed as the argument to creator.

public static final JsonCreator.Mode
DISABLED

Pseudo-mode that indicates that creator is not to be used.

public static final JsonCreator.Mode
PROPERTIES

Mode that indicates that the argument(s) for creator are to be bound from matching properties of incoming Object value, using creator argument names (explicit or implicit) to match incoming Object properties to arguments.

Constructor Summary

AccessConstructor and Description
private
Mode()

Method Summary

Modifier and TypeMethod and Description
public static JsonCreator.Mode
public static JsonCreator.Mode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DEFAULTback to summary
public static final JsonCreator.Mode DEFAULT

Pseudo-mode that indicates that caller is to use default heuristics for choosing mode to use. This typically favors use of delegating mode for single-argument creators that take structured types.

DELEGATINGback to summary
public static final JsonCreator.Mode DELEGATING

Mode that indicates that if creator takes a single argument, the whole incoming data value is to be bound into declared type of that argument; this "delegate" value is then passed as the argument to creator.

DISABLEDback to summary
public static final JsonCreator.Mode DISABLED

Pseudo-mode that indicates that creator is not to be used. This can be used as a result value for explicit disabling, usually either by custom annotation introspector, or by annotation mix-ins (for example when choosing different creator).

PROPERTIESback to summary
public static final JsonCreator.Mode PROPERTIES

Mode that indicates that the argument(s) for creator are to be bound from matching properties of incoming Object value, using creator argument names (explicit or implicit) to match incoming Object properties to arguments.

Note that this mode is currently (2.5) always used for multiple-argument creators; the only ambiguous case is that of a single-argument creator.

Constructor Detail

Modeback to summary
private Mode()

Method Detail

valueOfback to summary
public static JsonCreator.Mode valueOf(String name)
valuesback to summary
public static JsonCreator.Mode[] values()