Top Description Methods
com.fasterxml.jackson.annotation

public @Interface JsonUnwrapped

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

Annotation used to indicate that a POJO-valued property should be serialized "unwrapped" -- that is, if it would be serialized as Object value, its properties are instead included as properties of its containing Object -- and deserialized reproducing "missing" structure. 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. When values are deserialized "wrapping" is applied so that serialized output can be read back in.

Also note that annotation only applies if:

Specifically note that this annotation WILL NOT WORK for structured types like java.util.Maps or JsonNodes: for these types you will instead need to use JsonAnyGetter and JsonAnySetter to achieve similar operation.

Method Summary

Modifier and TypeMethod and Description
public boolean
enabled()

Property that is usually only used when overriding (masking) annotations, using mix-in annotations.

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

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

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

enabledback to summary
public 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.

prefixback to summary
public 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.

suffixback to summary
public 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.