JsonUnwrapped (Jackson-annotations 2.12.0 API)
Date: 2020-11-28

com.fasterxml.jackson.annotation

## Annotation Type JsonUnwrapped

-     @Target(value={ANNOTATION_TYPE,FIELD,METHOD,PARAMETER})
       @Retention(value=RUNTIME)
      public @interface JsonUnwrapped

  Annotation used to indicate that a property should be serialized "unwrapped"; that is, if it would be serialized as JSON Object, its properties are instead included as properties of its containing Object. For example, consider case of POJO like:

        public class Parent {
          public int age;
          public Name name;
        }
        public class Name {
          public String first, last;
        }

  which would normally be serialized as follows (assuming @JsonUnwrapped had no effect):

        {
          "age" : 18,
          "name" : {
            "first" : "Joey",
            "last" : "Sixpack"
          }
        }

  can be changed to this:

        {
          "age" : 18,
          "first" : "Joey",
          "last" : "Sixpack"
        }

  by changing Parent class to:

        public class Parent {
          public int age;
          @JsonUnwrapped
          public Name name;
        }

  Annotation can only be added to properties, and not classes, as it is contextual.

  Also note that annotation only applies if

  - Value is serialized as JSON Object (can not unwrap JSON arrays using this mechanism)
  - Serialization is done using `BeanSerializer`, not a custom serializer
  - No type information is added; if type information needs to be added, structure can not be altered regardless of inclusion strategy; so annotation is basically ignored.

- - ### Optional Element Summary

    Optional Elements
    Modifier and Type | Optional Element and Description
    --- | ---
    `boolean` | `enabled` Property that is usually only used when overriding (masking) annotations, using mix-in annotations.
    `String` | `prefix` Optional property that can be used to add prefix String to use in front of names of properties that are unwrapped: this can be done for example to prevent name collisions.
    `String` | `suffix` Optional property that can be used to add suffix String to append at the end of names of properties that are unwrapped: this can be done for example to prevent name collisions.

- - ### Element Detail

    - #### enabled

          public abstract boolean enabled

      Property that is usually only used when overriding (masking) annotations, using mix-in annotations. Otherwise default value of 'true' is fine, and value need not be explicitly included.
      Default:
        true

  - - #### prefix

          public abstract String prefix

      Optional property that can be used to add prefix String to use in front of names of properties that are unwrapped: this can be done for example to prevent name collisions.
      Default:
        ""

  - - #### suffix

          public abstract String suffix

      Optional property that can be used to add suffix String to append at the end of names of properties that are unwrapped: this can be done for example to prevent name collisions.
      Default:
        ""

Copyright © 2008–2020 FasterXML. All rights reserved.