001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.bind.annotation;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025import org.springframework.http.converter.HttpMessageConverter;
026
027/**
028 * Annotation indicating a method parameter should be bound to the body of the web request.
029 * The body of the request is passed through an {@link HttpMessageConverter} to resolve the
030 * method argument depending on the content type of the request. Optionally, automatic
031 * validation can be applied by annotating the argument with {@code @Valid}.
032 *
033 * <p>Supported for annotated handler methods in Servlet environments.
034 *
035 * @author Arjen Poutsma
036 * @since 3.0
037 * @see RequestHeader
038 * @see ResponseBody
039 * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
040 */
041@Target(ElementType.PARAMETER)
042@Retention(RetentionPolicy.RUNTIME)
043@Documented
044public @interface RequestBody {
045
046        /**
047         * Whether body content is required.
048         * <p>Default is {@code true}, leading to an exception thrown in case
049         * there is no body content. Switch this to {@code false} if you prefer
050         * {@code null} to be passed when the body content is {@code null}.
051         * @since 3.2
052         */
053        boolean required() default true;
054
055}