Add required flag to @RequestBody

If true and there is no body => HttpMessageNotReadableException
If false and there is no body, the argument resolves to null.

Issue: SPR-9239
This commit is contained in:
Rossen Stoyanchev
2012-05-17 17:48:48 -04:00
parent 0105c5ebb9
commit 77ae101402
4 changed files with 88 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,4 +44,12 @@ import org.springframework.http.converter.HttpMessageConverter;
@Documented
public @interface RequestBody {
/**
* Whether body content is required.
* <p>Default is <code>true</code>, leading to an exception thrown in case
* there is no body content. Switch this to <code>false</code> if you prefer
* <code>null</value> to be passed when the body content is <code>null</code>.
*/
boolean required() default true;
}