Benny
Benny

Reputation: 1465

Java JSON-Lib Set Field only one entry

I am having a correct JSON String which is made out of an Object A, containing a Set of other Objects B.

When I try to get back this Object now from the JSON String, the Set of Objects B will only have a single entry, instead of all the contained in the JSON String.

Any suggestions, or did I just do something forbidden??

Thanks

Upvotes: 0

Views: 160

Answers (1)

Benny
Benny

Reputation: 1465

For those who might fall over it, this solved the problem with the Set:

JSONArray jsonArray = JSONArray.fromObject(object);
JSONObject jsonObject = new JSONObject();
jsonObject.put("data", jsonArray.toString());

Upvotes: 0

Related Questions