Annotation Type FormData
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
Example:
This is functionally equivalent to the following code...
See Also:
Important note concerning FORM posts
This annotation should not be combined with the @Content
annotation or
The @Query
annotation can be used to retrieve a URL parameter in the URL string without triggering the
servlet to drain the body content.
Arguments and argument-types of client-side @RemoteResource-annotated interfaces
Annotation applied to Java method arguments of interface proxies to denote that they are FORM post parameters on the request.
See Also:
Methods and return types of server-side and client-side @Request-annotated interfaces
See Also:
@Content
annotation or The
@Query
annotation can be used to retrieve a URL parameter in the URL string without triggering the
servlet to drain the body content.
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
Modifier and TypeOptional ElementDescriptionDefault value for this parameter.FORM parameter name.String[]
Dynamically apply this annotation to the specified classes.Class<?>[]
Dynamically apply this annotation to the specified classes.Class<? extends HttpPartParser>
Specifies theHttpPartParser
class used for parsing strings to values.schema field of the Swagger Parameter Object.Class<? extends HttpPartSerializer>
Specifies theHttpPartSerializer
class used for serializing values to strings.A synonym forname()
.
-
Element Details
-
def
Default value for this parameter.- Returns:
- The annotation value.
- Default:
- ""
-
name
FORM parameter name.The name of the parameter (required).
The value should be either a valid form parameter name, or
"*" to represent multiple name/value pairsA 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 ("/addPet" )public void addPet(@FormData JsonMapallFormDataParameters ) {...}// When used on a remote method parameter @RemoteResource (path="/myproxy" )public interface MyProxy {// Equivalent to @FormData("*") @RemotePost ("/mymethod" ) String myProxyMethod1(@FormData Map<String,Object>allFormDataParameters ); }// When used on a request bean method public interface MyRequest {// Equivalent to @FormData("*") @FormData Map<String,Object> getFoo(); } -
If used on a request bean method, uses the bean property name.
Example:
public interface MyRequest {// Equivalent to @FormData("foo") @FormData String getFoo(); }
Notes:
- The format is plain-text.
- Returns:
- The annotation value.
- Default:
- ""
-
If the data type is
-
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
Class<? extends HttpPartParser> parserSpecifies theHttpPartParser
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 defining the type used for parameter.
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
-
serializer
Class<? extends HttpPartSerializer> serializerSpecifies theHttpPartSerializer
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 forname()
.Allows you to use shortened notation if you're only specifying the name.
The following are completely equivalent ways of defining a form post entry:
public Order placeOrder(@FormData (name="petId" )long petId ) {...}public Order placeOrder(@FormData ("petId" )long petId ) {...}- Returns:
- The annotation value.
- Default:
- ""
-