com.fasterxml.jackson.annotation

Annotation Type JsonCreator



  • @Target(value={ANNOTATION_TYPE,METHOD,CONSTRUCTOR})
    @Retention(value=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
    • Constructor/factory method where every argument is annotated with either JsonProperty or JacksonInject, to indicate name of property to bind to
    Also note that all JsonProperty annotations MUST use actual name (NOT empty String for "default"): this because Java bytecode does not retain names of method or constructor arguments.
    NOTE: as of JDK 8, some of above changes, with introduction of names for constructor and method parameters.

    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element and 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

        public abstract 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 JsonCreator.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

Copyright © 2014-2015 FasterXML. All Rights Reserved.