【发布时间】:2011-07-03 06:21:47
【问题描述】:
我有一个类似这样的 JSON:
objects:[{
id:"p452365",
type:"photo",
link:"http://xxx.zz"
},
{
id:"v7833",
type:"video",
link:"http://xxx.yy",
length:"4.12"
}
]
在超类 Entity 中,有 2 个实例变量:id 和 type。在我的扩展 XmlAdapter 类中,我尝试将我的 Entity 实例转换为 ex 的子类型。 Photo
public HashMap<String, List<Column>> unmarshal(Feeds f) throws Exception {
for(Feed feed : f.getFeeds()){
System.out.println("Entity id for feed : " + feed.getId());
for(Entity e:feed.getObjects()){
if (e instanceof Photo){
// Of course it's not
}
}
}
return (HashMap<String, List<Column>>)fm.map(f.getFeeds());
}
当然 e 不是 Photo 的实例,我在那里拍了一张。:) 我想做的是在某个时候干扰 JAXB 进程并根据 JSON 中的类型值解组。我想知道在哪里以及如何。
【问题讨论】:
标签: jaxb