Annotation Type Content


REST request body annotation.

Identifies a POJO to be used as the body of an HTTP request.

Can be used in the following locations:

  • Arguments and argument-types of server-side @RestOp-annotated methods.
  • Arguments and argument-types of client-side @RemoteOp-annotated interfaces.
  • Methods and return types of server-side and client-side @Request-annotated interfaces.
Arguments and argument-types of server-side @RestOp-annotated methods

On server-side REST, this annotation can be applied to method parameters or parameter classes to identify them as the body of an HTTP request.

Examples:

// Used on parameter @RestPost("/pets") public void addPet(@Content Pet pet) {...}

// Used on class @RestPost("/pets") public void addPet(Pet pet) {...} @Content public class Pet {...}

This is functionally equivalent to the following code...

@RestPost("/pets") public void addPet(RestRequest req) { Pet pet = req.getContent().as(Pet.class); ... }

Arguments and argument-types of client-side @RemoteResource-annotated interfaces
See Also:
Methods and return types of server-side and client-side @Request-annotated interfaces
See Also:
Notes:
  • Annotation parameter values will be aggregated when used on POJO parent and child classes.
    Values on child classes override values on parent classes.
  • Annotation parameter values will be aggregated when used on both POJOs and REST methods.
    Values on methods override values on POJO classes.
  • If using this annotation on a Spring bean, note that you are likely to encounter issues when using on parameterized types such as List<MyBean>. This is due to the fact that Spring uses CGLIB to recompile classes at runtime, and CGLIB was written before generics were introduced into Java and is a virtually-unsupported library. Therefore, parameterized types will often be stripped from class definitions and replaced with unparameterized types (e.g. List). Under these circumstances, you are likely to get ClassCastExceptions when trying to access generalized JsonMaps as beans. The best solution to this issue is to either specify the parameter as a bean array (e.g. MyBean[]) or declare the method as final so that CGLIB will not try to recompile it.
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Dynamically apply this annotation to the specified classes.
    Class<?>[]
    Dynamically apply this annotation to the specified classes.
    schema field of the Swagger Parameter Object.
  • Element Details

    • on

      Dynamically apply this annotation to the specified classes.
      See Also:
      Returns:
      The annotation value.
      Default:
      {}
    • onClass

      Dynamically apply this annotation to the specified classes.

      Identical to on() except allows you to specify class objects instead of a strings.

      See Also:
      Returns:
      The annotation value.
      Default:
      {}
    • schema

      schema field of the Swagger Parameter Object.

      The schema defining the type used for parameter.

      This is a required attribute per the swagger definition. However, if not explicitly specified, the value will be auto-generated using JsonSchemaSerializer.

      The @Schema annotation can also be used standalone on the parameter or type. Values specified on this field override values specified on the type, and values specified on child types override values specified on parent types.

      Used for:
      • Server-side schema-based parsing and parsing validation.
      • Server-side generated Swagger documentation.
      • Client-side schema-based serializing and serializing validation.
      Returns:
      The annotation value.
      Default:
      @org.apache.juneau.annotation.Schema