0

In my requirement I am reading JsonArray (javax.json.JsonArray) from the local file like below:

JsonReader reader = Json.createReader(new FileReader(path));
JsonArray regAttribArr = reader.readObject().getJsonObject("Entries")
                .getJsonArray("Attributes");
reader.close();

After that while removing the element from that array like below,

JsonValue tempjv = regAttribArr.get(0);
regAttribArr.remove(tempjv);

it is throwing UnsupportedOperationException as JsonArray class is unmodifiable list.

Is there any alternate way to delete the element from this javax.json.JsonArray object ?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Krutik
  • 1,107
  • 13
  • 18
  • The `javax.json` JSON types are immutable. You'll have to build copies yourself ("copies" that don't include what you want to remove). – Sotirios Delimanolis Sep 23 '16 at 16:13
  • In my requirement I am having the list of json objects coming from request payload,each of which are one by one compared with the list of json objects read from the file. Whenever the match found for any of the json object that object needs to be remove from the JsonArray read from the file.As per the comment every time it needs to traverse as well as need to create new jsonarray object.So it will be much time consuming. – Krutik Sep 23 '16 at 18:48

1 Answers1

1

Seems like you may be better off copying the list item-by-item and skipping over the one you don't want.

An unmodifiable list is just going to be unmodifiable