Add protected method for required RequestBody

This commit is contained in:
Rossen Stoyanchev 2016-02-05 02:24:03 -05:00
parent 7756feacd8
commit e4539d9f40
1 changed files with 6 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -146,7 +146,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
Object arg = readWithMessageConverters(inputMessage, methodParam, paramType); Object arg = readWithMessageConverters(inputMessage, methodParam, paramType);
if (arg == null) { if (arg == null) {
if (methodParam.getParameterAnnotation(RequestBody.class).required()) { if (checkRequired(methodParam)) {
throw new HttpMessageNotReadableException("Required request body is missing: " + throw new HttpMessageNotReadableException("Required request body is missing: " +
methodParam.getMethod().toGenericString()); methodParam.getMethod().toGenericString());
} }
@ -154,6 +154,10 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
return arg; return arg;
} }
protected boolean checkRequired(MethodParameter methodParam) {
return methodParam.getParameterAnnotation(RequestBody.class).required();
}
@Override @Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, public void handleReturnValue(Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) ModelAndViewContainer mavContainer, NativeWebRequest webRequest)