![JAR search and dependency download from the Maven repository](/logo.png)
org.apache.juneau.http.annotation.Content 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.http.annotation;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.json.*;
/**
* 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:
* - @Content
*
*
* Methods and return types of server-side and client-side @Request-annotated interfaces
*
* See Also:
* - @Request
*
*
* 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:
*
*/
@Documented
@Target({PARAMETER,METHOD,TYPE})
@Retention(RUNTIME)
@Inherited
@Repeatable(ContentAnnotation.Array.class)
@ContextApply(ContentAnnotation.Applier.class)
public @interface Content {
/**
* Dynamically apply this annotation to the specified classes.
*
* See Also:
*
* @return The annotation value.
*/
String[] on() default {};
/**
* Dynamically apply this annotation to the specified classes.
*
*
* Identical to {@link #on()} except allows you to specify class objects instead of a strings.
*
*
See Also:
*
* @return The annotation value.
*/
Class>[] onClass() default {};
/**
* 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 {@link JsonSchemaSerializer}.
*
*
* The {@link Schema @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.
*
*
* @return The annotation value.
*/
Schema schema() default @Schema;
}