All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.jackson.annotate.JsonUnwrapped Maven / Gradle / Ivy

There is a newer version: 1.1.6
Show newest version
package org.codehaus.jackson.annotate;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 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 *
  • *
  • 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. *
  • *
* * @since 1.9 */ @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonUnwrapped { /** * 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. */ boolean enabled() default true; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy