我有一个简单的课程。
public class SolrModel {
private Base64 param;
//setter
public Base64 getParam() {
return param;
}
//getter
public void setParam(Base64 param) {
this.param = param;
}
public SolrModel(Base64 param) {
this.param = param;
}
public SolrModel() {
}
}
这是一个处理POST请求的控制器类。
@RestController
public class SolrController {
@RequestMapping(value = "/getdata", method = RequestMethod.POST)
public SolrDocumentList getStatus(@RequestBody SolrModel sm) {
SolrAction sa = new SolrActionImpl();
return sa.getSearchData(sm.getName());
}
}
在我进行REST调用之后,服务抛出异常。
WARNING: Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not instantiate value of type [simple type, class java.util.Base64] from String value ('dmlub2Q='); no single-String constructor/factory method
at [Source: java.io.PushbackInputStream@4d809754; line: 2, column: 18] (through reference chain: test.solr.models.SolrModel["param"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class java.util.Base64] from String value ('dmlub2Q='); no single-String constructor/factory method
at [Source: java.io.PushbackInputStream@4d809754; line: 2, column: 18] (through reference chain: test.solr.models.SolrModel["param"])
Aug 12, 2015 7:22:40 PM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver logException
WARNING: Handler execution resulted in exception: Could not read document: Can not instantiate value of type [simple type, class java.util.Base64] from String value ('dmlub2Q='); no single-String constructor/factory method
at [Source: java.io.PushbackInputStream@4d809754; line: 2, column: 18] (through reference chain: test.solr.models.SolrModel["param"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class java.util.Base64] from String value ('dmlub2Q='); no single-String constructor/factory method
at [Source: java.io.PushbackInputStream@4d809754; line: 2, column: 18] (through reference chain: test.solr.models.SolrModel["param"])
解决这个问题的方法是什么?