Package com.fasterxml.jackson.annotation
Annotation Type JsonCreator
-
@Target({ANNOTATION_TYPE,METHOD,CONSTRUCTOR}) @Retention(RUNTIME) public @interface JsonCreator
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:
- Single-argument constructor/factory method without
JsonProperty
annotation for the argument: if so, this is so-called "delegate creator", in which case Jackson first binds JSON into type of the argument, and then calls creator. This is often used in conjunction withJsonValue
(used for serialization). - Constructor/factory method where every argument is annotated with
either
JsonProperty
orJacksonInject
, to indicate name of property to bind to
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 usingJsonValue
.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
- Single-argument constructor/factory method without
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description JsonCreator.Mode
mode
Property that is used to indicate how argument(s) is/are bound for creator, in cases there may be multiple alternatives.
-
-
-
Element Detail
-
mode
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. CheckJsonCreator.Mode
for more complete explanation of possible choices.Default value of
JsonCreator.Mode.DEFAULT
means that caller is to use standard heuristics for choosing mode to use.- Since:
- 2.5
- Default:
- com.fasterxml.jackson.annotation.JsonCreator.Mode.DEFAULT
-
-