有人可以告诉我为什么我会收到 org.codehaus.jackson.map.JsonMappingException:找不到适合类型错误的构造函数吗?
这是我的电话:
try
{
String jsonreturn = restTemplate.getForObject("http://" + mRESTServer.getHost() + ":8080/springmvc-rest-secured-test/json/{name}", String.class, vars);
LOGGER.debug("return object: " + jsonreturn.toString());
} catch (HttpClientErrorException e)
{
/**
*
* If we get a HTTP Exception display the error message
*/
LOGGER.error("error: " + e.getResponseBodyAsString());
ObjectMapper mapper = new ObjectMapper();
ErrorHolder eh = mapper.readValue(e.getResponseBodyAsString(), ErrorHolder.class);
LOGGER.error("error: " + eh.errorMessage);
}
我正在尝试测试错误,所以我应该创建一个 ErrorHolder 对象,但我收到了错误;
这是我的 ErrorHolder 类:
public class ErrorHolder
{
public String errorMessage;
public ErrorHolder(String errorMessage)
{
this.errorMessage = errorMessage;
}
public String getErrorMessage()
{
return errorMessage;
}
public void setErrorMessage(String errorMessage)
{
this.errorMessage = errorMessage;
}
@Override
public String toString()
{
return "ErrorHolder{" +
"errorMessage='" + errorMessage + '\'' +
'}';
}
}
我不知道为什么会出现以下错误:
2013-06-12 14:36:32,138 [main] ERROR Main - error: {"errorMessage":"Uh oh"}
Exception in thread "main" org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class ErrorHolder]: can not instantiate from JSON object (need to add/enable type information?)
at [Source: java.io.StringReader@628016f7; line: 1, column: 2]