Could not convert value of type "java.lang.String" to required type
Im executing the following code will display an error message. How do I resolve this error?
@RequestMapping(value = "/Testresult", method = RequestMethod.POST)
@ResponseBody
public String testresult(
HttpServletRequest request,
@Valid TestCustomer<Customer> req
,BindingResult resultMsg)
{
String content = "";
if(resultMsg.hasFieldErrors() ){
System.out.println("the error counts:" + resultMsg.getErrorCount());
}
return resultMsg.getErrorCount;
}
//TestCustomer.java
public class TestCustomer<T> extends BaseUser {
@Valid
private T req;
public T getReq() {
return req;
}
public void setReq(T req) {
this.req = req;
}
}
//BaseUser.java
public class BaseUser {
@Size(min=3, max=20)
private String app;
public String getApp() {
return app;
}
public void setApp(String app) {
this.app = app;
}
}
//Customer.java
public class Customer implements Serializable{
@Size(min=3, max=4)
private String cust_id;
private String order_id;
public String getCust_id() {
return cust_id;
}
public void setCust_id(String cust_id) {
this.cust_id = cust_id;
}
public String getOrder_id() {
return order_id;
}
public void setOrder_id(String order_id) {
this.order_id = order_id;
}
}
I am posting the following url
http: // localhost: 8080 / jd / order / Testresult? app = 122 & req = {\ "cust_id \": \ "\", \ "order_id \": \ "122 \"}
Firefox poster error:
/ * ["timestamp": 1436514495544, "status": 500, "error": "Internal server error", "exception": "org.springframework.beans.ConversionNotSupportedException", "message": "Unable to convert value of type" java.lang.String "to the required type" cn.vcredit.jd.emergencymoney.restservice.TestCustomer "; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [cn.vcredit .jd.emergencymoney.restservice.TestCustomer]: no matching editors found or conversion strategy "] * /
source to share
No one has answered this question yet
Check out similar questions: