Annotation Type Query


REST request form-data annotation.

Identifies a POJO to be used as a form-data entry on 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 @RemoteResource-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

Annotation that can be applied to a parameter of a @RestOp-annotated method to identify it as a URL query parameter.

Unlike @FormData, using this annotation does not result in the servlet reading the contents of URL-encoded form posts. Therefore, this annotation can be used in conjunction with the @Content annotation or RestRequest.getContent() method for application/x-www-form-urlencoded POST calls.

Example:

@RestGet public void doGet( @Query("p1") int p1, @Query("p2") String p2, @Query("p3") UUID p3 ) {...}

This is functionally equivalent to the following code...

@RestGet public void doGet(RestRequest req, RestResponse res) { int p1 = req.getQueryParam("p1").asInteger().orElse(0); String p2 = req.getQueryParam("p2").asString().orElse(null); UUID p3 = req.getQueryParam("p3").as(UUID.class).orElse(null); ... }

See Also:
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:

  • Element Details

    • def

      Default value for this parameter.
      Returns:
      The annotation value.
      Default:
      ""
    • name

      URL query parameter name. Required. The name of the parameter. Parameter names are case sensitive.

      The value should be either a valid query parameter name, or "*" to represent multiple name/value pairs

      A blank value (the default) has the following behavior:

      • If the data type is NameValuePairs, Map, or a bean, then it's the equivalent to "*" which will cause the value to be serialized as name/value pairs.
        Examples:

        // When used on a REST method @RestPost public void addPet(@Query JsonMap allQueryParameters) {...}

        // When used on a remote method parameter @RemoteResource(path="/myproxy") public interface MyProxy { // Equivalent to @Query("*") @RemoteGet("/mymethod") String myProxyMethod1(@Query Map<String,Object> allQueryParameters); }

        // When used on a request bean method public interface MyRequest { // Equivalent to @Query("*") @Query Map<String,Object> getFoo(); }

      • If used on a request bean method, uses the bean property name.
        Example:

        public interface MyRequest { // Equivalent to @Query("foo") @Query String getFoo(); }

      Notes:
      • The format is plain-text.
      Returns:
      The annotation value.
      Default:
      ""
    • 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:
      {}
    • parser

      Specifies the HttpPartParser class used for parsing strings to values.

      Overrides for this part the part parser defined on the REST resource which by default is OpenApiParser.

      Returns:
      The annotation value.
      Default:
      org.apache.juneau.httppart.HttpPartParser.Void.class
    • schema

      schema field of the Swagger Parameter Object.

      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.

      The schema defining the type used for parameter.

      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
    • serializer

      Specifies the HttpPartSerializer class used for serializing values to strings.

      Overrides for this part the part serializer defined on the REST client which by default is OpenApiSerializer.

      Returns:
      The annotation value.
      Default:
      org.apache.juneau.httppart.HttpPartSerializer.Void.class
    • value

      A synonym for name().

      Allows you to use shortened notation if you're only specifying the name.

      The following are completely equivalent ways of defining the existence of a query entry:

      public Order placeOrder(@Query(name="petId") long petId) {...}

      public Order placeOrder(@Query("petId") long petId) {...}

      Returns:
      The annotation value.
      Default:
      ""