I've a JSON something like this:
objects:[{
id:"p452365",
type:"photo",
link:"http://xxx.zz"
},
{
id:"v7833",
type:"video",
link:"http://xxx.yy",
length:"4.12"
}
]
In superclass Entity
, there're 2 instance variables: id and type. In my extended XmlAdapter
class I tried to cast my Entity instances to a subtype for 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());
}
Of course e isn't an instanceof Photo, I took a shot there.:) What I wanna do is to interfere the JAXB process sometime and unmarshall according to the type value in JSON.I wonder where and how.