I am developing a Spring MVC web application. I am not still develop the UI. So I am testing my services using Advance Rest Client tool.
My Controller
@Controller
@RequestMapping("/testController")
public class TestController {
@Autowired
private TestService testService;
@RequestMapping(value = "/test", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public
@ResponseBody void testMethod(@RequestBody TestParam testParam) {
String tenant = testParam.getTenantCode();
String testString = tenant + " is the tenant";
}
}
TestParam.java class
public class TestParam {
private String testVar;
private String tenantCode;
public String getTenantCode() {
return tenantCode;
}
public void setTenantCode(String tenantCode) {
this.tenantCode = tenantCode;
}
public String getTestVar() {
return testVar;
}
public void setTestVar(String testVar) {
this.testVar = testVar;
}
}
I send the request using Advance Rest Client and headers and request link has set correctly.
{"testVar":"Test","tenantCode":"DEMO"}
Request link
http://localhost:8080/myApp/controller/testController/test
It works correctly when TestParam has one veriable. When it becomes two or more it gives an Error and it not hit the testMethod.
exception is com.fasterxml.jackson.core.JsonParseException: Unexpected end-of-input in field name at [Source:org.apache.catalina.connector.CoyoteInputStream@7b24d498; line: 1, column: 43]
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:181)
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.read(MappingJackson2HttpMessageConverter.java:173)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:135)
I went throw more articles and I still couldn't find the answer.
Increasing Content-Length:
in header
works