From e4539d9f4003bee0f3cd31dd70b87a32ffb95884 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 5 Feb 2016 02:24:03 -0500 Subject: [PATCH] Add protected method for required RequestBody --- .../annotation/RequestResponseBodyMethodProcessor.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java index bc187962c5..b69911a832 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java @@ -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"); * 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); if (arg == null) { - if (methodParam.getParameterAnnotation(RequestBody.class).required()) { + if (checkRequired(methodParam)) { throw new HttpMessageNotReadableException("Required request body is missing: " + methodParam.getMethod().toGenericString()); } @@ -154,6 +154,10 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter return arg; } + protected boolean checkRequired(MethodParameter methodParam) { + return methodParam.getParameterAnnotation(RequestBody.class).required(); + } + @Override public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest)