I'm using JDK 1.8.0_101 and added javax.json.jar to classpath. The below compiles just fine but throws an error. It looks like the remove() method has not been implemented.
public class Test{
public static void main(String[] args) {
javax.json.JsonObject o = javax.json.Json.createObjectBuilder().add("a", 1).add("b", 2).build();
try {
o.remove("a");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
This is the output:
java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$1.remove(Collections.java:1664)
at java.util.AbstractMap.remove(AbstractMap.java:254)
at Test.main(Test.java:5)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
How can I fix it or when can I expect this method to be implemented? Am I using an old version of the javax.json library?