问题描述
我正在开发Spring MVC Web应用程序.我还没有开发UI.因此,我正在使用Advance Rest Client工具测试我的服务.
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.
我的控制器
@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类
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;
}
}
我使用Advance Rest Client和标头发送请求,并且请求链接已正确设置.
I send the request using Advance Rest Client and headers and request link has set correctly.
{"testVar":"Test","tenantCode":"DEMO"}
请求链接
http://localhost:8080/myApp/controller/testController/test
当TestParam具有一个veriable时,它可以正常工作.当它变成两个或两个以上时,它会给出错误,并且不会命中testMethod.
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.
推荐答案
在header
中增加Content-Length:
的效果
这篇关于无法读取JSON:字段名称输入意外结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!