Permission resolution issues when using the GSON library in an applet

I am writing an applet that calls some JSON-RPC calls. I am using the Google JSON library (GSON) to pass the JSON response to the class. Thsi seems to work fine as it is, but when I use this code in my applet, it amazes me java.lang.reflect.reflectpermission. From what I read in this thread on SO, it seems that since GSON uses Reflection, I cannot use it in Applets unless I explicitly change the security policy. How can I get around this? I created a bunch of classes in my application and used the method Gson.fromJsonto pass it to the class. Is there a way to achieve the same functionality without rewriting half of my code.

(The complexity of working with JSON in Java seems to be in the league!)

Thanks in advance guys.

+3
source share
2 answers

Some Java JSON libraries do have a stunning complex, especially given the simplicity of JSON itself. In my opinion http://www.json.org/java/index.html is the best library and does not do any fancy tricks, it simply analyzes JSON in its own special structure and what It is. This, of course, means that you need to make specific code to turn the hierarchy of JSON objects into what you use, but it should not be so difficult.

GSON JSON- XStream ( JSON) .

0

, AccessController#doPrivileged():

public void init() {
    AccessController.doPrivileged(new PrivilegedAction<Object> {
        @Override public Object run() {
            // Put your original init() here.
            return null;
        }
    });
}
0

Source: https://habr.com/ru/post/1744486/


All Articles