有人能告诉我如何在我的“RoboSpice”中使用RequestResult.java进行动态映射吗?
我的JSON看起来要么是这样的:
"result": [
{
"attributeX1" "...",
"type": "x",
"attributeXi" "..."
},
{
"attributeX1": "...",
"type": "x",
"attributeXi": "..."
}
]或
"result": [
{
"attributeY1" "...",
"type": "y",
"attributeYi" "..."
},
{
"attributeY1" "...",
"type": "y",
"attributeYi" "..."
}
]因此,如果" type ":"x“,我必须使用模型"x.java”,如果"type“:"y”需要使用"y.java“模型
发布于 2014-03-12 08:43:32
这完全取决于您正在使用的JSON库。Jackson 2提供了一种多态类型,您可能会感兴趣:http://programmerbruce.blogspot.com.es/2011/05/deserialize-json-with-jackson-into.html
官方医生来了:http://wiki.fasterxml.com/JacksonPolymorphicDeserialization
https://stackoverflow.com/questions/21851252
复制相似问题