Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not read JSON: Unexpected end-of-input in field name

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.

like image 568
Kasun Kariyawasam Avatar asked Apr 19 '16 13:04

Kasun Kariyawasam


2 Answers

Increasing Content-Length: in header works

like image 193
Kasun Kariyawasam Avatar answered Oct 19 '22 02:10

Kasun Kariyawasam


Whats your json format ? I think json format uses literal \n's as delimiters, please be sure that the JSON actions and sources are not pretty printed.

like image 2
EL missaoui habib Avatar answered Oct 19 '22 02:10

EL missaoui habib