Reputation: 473
I want to create a JSON string piece by piece and by using org.json.simple.JSONArray and org.json.simple.JSONObject. Here's the code.
1. JSONObject config = new JSONObject();
2. JSONArray urls = new JSONArray();
3. urls.add("https://www.test1.com/v1");
4. urls.add("https://www.test1.com/v2");
5. config.put("name", "name-test1");
6. config.put("sipUrls", sipUrls);
There is Eclipse warning for line 2 and 3:
And warning for line 5 and 6:
How can I get rid of these warnings?
P.S.
The problem addressed here is different from this How to correctly use HashMap? because there's no way to create a JSONArray<String> or JSONObject<String>. JSONArray and JSONObject are not parameterizable.
Upvotes: 3
Views: 1879
Reputation: 473
It appears that there's no way to parameterize org.json.simple.JSONArray and org.json.simple.JSONObject by its design. However, you can suppress these warnings by annotation:
@SuppressWarnings("unchecked")
Upvotes: 3