org.apache.juneau.rest.annotation.Query Maven / Gradle / Ivy
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
// * with the License. You may obtain a copy of the License at *
// * *
// * http://www.apache.org/licenses/LICENSE-2.0 *
// * *
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
// * specific language governing permissions and limitations under the License. *
// ***************************************************************************************************************************
package org.apache.juneau.rest.annotation;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.*;
import org.apache.juneau.rest.*;
/**
* Identical to {@link FormData @FormData}, but only retrieves the parameter from the URL string, not URL-encoded form
* posts.
*
*
* Unlike {@link FormData @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 {@link Body @Body} annotation or
* {@link RestRequest#getBody()} method for application/x-www-form-urlencoded POST
calls.
*
*
Example:
*
* @RestMethod (name=GET )
* public void doGet(RestRequest req, RestResponse res,
* @Query ("p1" ) int p1, @Query ("p2" ) String p2, @Query ("p3" ) UUID p3) {
* ...
* }
*
*
*
* This is functionally equivalent to the following code...
*
* @RestMethod (name=GET )
* public void doGet(RestRequest req, RestResponse res) {
* int p1 = req.getQueryParameter(int .class , "p1" , 0);
* String p2 = req.getQueryParameter(String.class , "p2" );
* UUID p3 = req.getQueryParameter(UUID.class , "p3" );
* ...
* }
*
*/
@Documented
@Target(PARAMETER)
@Retention(RUNTIME)
@Inherited
public @interface Query {
/**
* URL query parameter name.
*/
String name() default "";
/**
* A synonym for {@link #name()}.
*
*
* Allows you to use shortened notation if you're only specifying the name.
*/
String value() default "";
/**
* Specify true if using multi-part parameters to represent collections and arrays.
*
*
* Normally, we expect single parameters to be specified in UON notation for representing collections of values
* (e.g. "&key=(1,2,3)" .
* This annotation allows the use of multi-part parameters to represent collections
* (e.g. "&key=1&key=2&key=3" .
*
*
* This setting should only be applied to Java parameters of type array or Collection.
*/
boolean multipart() default false;
/**
* The expected format of the request parameter.
*
*
* Possible values:
*
* -
*
"UON" - URL-Encoded Object Notation.
*
This notation allows for request parameters to contain arbitrarily complex POJOs.
* -
*
"PLAIN" - Plain text.
*
This treats request parameters as plain text.
*
Only POJOs directly convertible from Strings can be represented in parameters when using this mode.
* -
*
"INHERIT" (default) - Inherit from the {@link RestResource#paramFormat()} property on the
* servlet method or class.
*
*
*
* Note that the parameter value "(foo)" is interpreted as "(foo)" when using plain mode, but
* "foo" when using UON mode.
*/
String format() default "INHERIT";
/**
* The default value for this query parameter if it's not present in the request.
*/
String def() default "";
}