Skip to content

Spring Controller is not able to detect empty string ("") as a string object in RequestBody [SPR-13861] #18434

@spring-projects-issues

Description

@spring-projects-issues

AVINABA GHOSH HAJRA opened SPR-13861 and commented

Problem Statement :
Spring Controller is not able to detect empty string ("") as a string object in RequestBody.Till Spring 3.2 Spring Controller is able to detect empty string ("") as a string. But now we upgrade our spring version from 3.2 to 4.2.And in Spring 4.2 we are facing this issue.Our API gives HTTP status 400 as response instead of processing the empty string in RequestBody
Example :
Controller Method definition:

   @MethodInfo(comments = DocumentationConstants.submitAttemptComments, date = "Mar 31 2014", summary = "Submits an Activity", sequence = 5 )
@RequestMapping(value ="/submit", method=RequestMethod.POST,produces="application/json")
@ResponseBody
public ResponseEntity<String> submitAttempt(@RequestBody String eaid)

And JUNIT ::

   @Test
public void testCase() throws Exception {
                 String eaid = "";
                                                                                 when(securityServiceMock.validateEAID(anyString())).thenReturn(false);	
     Map<String, String> jsonMap = new HashMap<String, String>();
     jsonMap.put("success", "true");
     when(assignmentServiceMock.getAjsonInfo(anyString(), anyBoolean())).thenReturn(new JSONObject(jsonMap));
     MvcResult result = this.mockMvcAssgnmntMock.perform(post("/caa/activity/submit")
               .content(eaid)
               .accept(MediaType.parseMediaType("application/json;charset=utf-8")))
               .andExpect(status().isNotAcceptable()).andReturn();
     _logger.info("Result received:" + result.getResponse().getContentAsString());
     assertEquals("{\"message\":\"EAID is acceptable\",\"status\":\"200\"}", result.getResponse().getContentAsString());
}

is giving error ::
java.lang.AssertionError: Status expected:<200> but was:<400>


Affects: 4.2 GA

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions