我创建了一个Rest服务,它在XML请求中运行良好(生成的类)。当我试图发送Json请求时,它会抛出一个异常。
SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class Transaction] from JSON String; no single-String constructor/factory method (through reference chain:
class Transaction which is inner class .我的请求类是使用JAXB从模式生成的,我的getter方法如下所示,但没有setter方法。
public List<Transaction> getORIG() {
if (origtrans == null) {
origtrans = new ArrayList<Transaction>();
}
return this.origtrans;
}我的Json请求如下
{
"LOB_CD": "42424"
"ORIGINALTRANSACTION" : [
"LOGON_ID" : "TEST"
]
}当我是加法原始事务时,它会抛出一个错误,否则它会正常工作。
你能帮帮我吗。提前谢谢。
发布于 2015-03-05 19:35:52
首先,确保您使用的是有效的JSON,例如:
{
"LOB_CD": "42424",
"ORIGINALTRANSACTION": {
"LOGON_ID": "TEST"
}
}另外,如果您能够向我们展示事务类,那就太好了。
发布于 2015-03-05 21:02:11
它起作用了。我按照步骤1)添加了一个空的构造函数2)为列表添加了这个注释
@JsonDeserialize(as=ArrayList.class, contentAs=Transaction.class)3)将Json对象更改为{ "LOB_CD": "42424" "ORIGINALTRANSACTION" : [ { "LOGON_ID" : "TEST" } ] }
非常感谢,帕特尔
https://stackoverflow.com/questions/28885491
复制相似问题