I am working with Oracle OPAM and it has a REST API that has methods like this
{
"Target Collection":[
{
"target":{
"uri":"https:\/\/opam_server_host:opam_ssl_port\/opam\/target\
/9bbcbbb087174ad1900ea691a2573b61",
"type":"ldap",
"name":"person1-ldap",
"host":"opam_server_host",
"domain":"berkeley"
"description" : "Ldap target"
}
},
{
"target":{
"uri":"https:\/\/opam_server_host:opam_ssl_port\/opam\/target\
/ac246a162ce948c7b1cdcc17dfc92c15",
"type":"ldap",
"name":"person1-ldap2",
"host":"opam_server_host:opam_ssl_port",
"domain":"berkeley"
"description" : "Ldap target"
}
}
]
}
I am using FlexJSON to deserialize these entities. If I could, I'd use Apache CXF to generate the beans for me, but the problem is that the WADL is under an invalid https certificate + basic authentication, and getting wadl2java to work under these conditions are taking more time than I'd like to spend (too bad it isn't WSDL, so I could just create the stubs from inside eclipse fast and easy).
So I am using this cumbersome approach with flexjson to parse this REST API
JSONDeserializer<Map<String,List<Map<String,Map<String,String>>>>> json = new JSONDeserializer<>();
Map<String,List<Map<String,Map<String,String>>>> targetCollection = json.deserialize(new InputStreamReader(content));
List<Map<String,Map<String,String>>> col = targetCollection.get("Target Collection"); Map<String,Map<String,String>> keyVal = col.get(0);
Map<String,String> targetVal = keyVal.get("target");
System.out.println(targetVal);
This obviously works, but it has so many brackets that reminds me LISP.
It would be so much better if we could just use POJOs instead (even better if I could have then generated automatically by some GUI tool, but I know I am asking too much, we're living in 2014).
I know there is some documentation about how to map attributes here : http://flexjson.sourceforge.net/#Deserialization but I really wish they have some real complex sample (including the JSON - what's the use of explaining how to deserialize without any JSON example in the documentation?)
This question is obviously not new, but it seems that related questions like 1, 2 or 3 are also waiting for an answer.
(P.S. except this one seems to have some info I can use)
So my question is: how do I parse this JSON with FlexJSON into a structure not only made of Maps?