Annotation Type StatusCode


REST response status annotation.

Annotation used to denote an HTTP response status code.

Can be used in the following locations:

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

On server-side REST, this annotation can be applied to method parameters to identify them as an HTTP response value.

Example:

@RestPost public void addPet(@Content Pet pet, @StatusCode Value<Integer> status) { addPet(pet); status.set(200); }

The parameter type must be Value with a parameterized type of Integer.

Public methods of @Response-annotated types

On @Response-annotated classes, this method can be used to denote an HTTP status code on a response.

Example:

@RestPost public Success addPet(Pet pet) { addPet(pet); return new Success(); }

@Response public class Success { @StatusCode public int getStatus() { return 201; } @Override public String toString() { return "Pet was successfully added"; } }

The method being annotated must be public and return a numeric value.

See Also:
Methods and return types of server-side and client-side @Response-annotated interfaces
See Also:

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.
    int[]
    The HTTP response codes.
  • 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:
      {}
    • value

      int[] value
      The HTTP response codes. The default value is 500 for exceptions and 200 for return types.
      Returns:
      The annotation value.
      Default:
      {}