Say I have the following JSON string returned from server:
{
"response":{
"imageInstances":{
"one":{
"id":"1",
"url":"ONE"
},
"two":{
"id":"2",
"url":"TWO"
}
}
}
}
in codehaus Jackson @JsonProperty, how can I get a HashMap object out of it?
import org.codehaus.jackson.annotate.JsonAnySetter;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.HashMap;
import java.util.List;
public class MSShow {
@JsonProperty("imageInstances") private HashMap<String, Temp> images;//// HOW DO YOU CONVERT IT TO HASH MAP??????
@JsonAnySetter public void ignoredField(String key, Object value) { }
private class Temp {
@JsonProperty("id") private String id;
@JsonProperty("url") private String url;
@JsonAnySetter public void ignoredField(String key, Object value) { }
}
}
At the end of the day, I want the hash map generated based on the returned JSON string to be (written in java pseudo)
should return me a Temp object with fields id=1 and url=ONE if I call
images.get("one")
should return me a Temp object with fields id=2 and url=TWO if I call
images.get("two")
Tempbeing a) private, and b) an inner class (non-static, hence bound to the instance of the containingMediaSlideShow). So I'd start with makingTemppublic static.HashMap? If not, consider aMap<String, Temp>instead and let Jackson worry about what implementation to use.