在小程序使用GSON库时,反射的权限问题 [英] Reflection Permission problems when using the GSON library in a applet

查看:214
本文介绍了在小程序使用GSON库时,反射的权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个applet,使得一些JSON-RPC调用。我使用的是谷歌JSON库(GSON),以响应JSON浇铸成一个类。 Thsi似乎做工精细的是,但是当我在我的小程序使用code,我被击中了 java.lang.reflect.reflectpermission 。从我在<读href=\"http://stackoverflow.com/questions/2213734/using-gson-library-in-gwt-client-$c$c/2260864#2260864\">this螺纹对SO,似乎因为GSON使用反射,我不能用它的小程序,除非我明确地修改安全策略。我怎样才能解决这个问题?我创建了一堆在我的应用程序类,并使用 Gson.fromJson 方法将其抛入类。有没有什么办法,而无需重新编写我的一半code来实现相同的功能。

I'm writing an Applet that makes some JSON-RPC calls. I'm using the Google JSON library (GSON) to cast the response JSON into a class. Thsi seems to work fine as is but when I use this code in my Applet, I'm hit with a java.lang.reflect.reflectpermission. From what I read on this thread on SO, it seems that since GSON uses Reflection, I cannot use it in Applets unless I explicitly modify the security policy. How can I get around this? I've created a bunch of classes in my application and was using the Gson.fromJson method to cast it into the class. Is there any way to achieve the same functionality without having to re-write half my code.

(将使用JSON在Java中处理的复杂性,似乎是在它自己的联赛!)

(The complexity of dealing with JSON in Java seems to be in a league of its own!)

在此先感谢球员。

推荐答案

用于Java的一些JSON库确实头脑麻木复杂尤其是考虑到JSON本身的简单性。在我看来, http://www.json.org/java/index.html 是最好的图书馆,并没有做任何花哨的招数,只是解析JSON到它自己的特殊结构,这就是它。当然,这意味着你必须做出具体code打开JSON对象层次来使用的东西,但不应该是那么难。

Some JSON libraries for Java are indeed mind numbingly complex especially considering the simplicity of JSON itself. In my opinion http://www.json.org/java/index.html is the best library and doesn't do any fancy tricks, just parses the JSON into its own special structure and that's it. This of course means you have to make specific code to turn the JSON Object hierarchy to something you use but that shouldn't be that hard.

GSON是 XStream的(它可以做JSON的静脉更多基于JSON的持久性太)和声音有点过于重量级只是一个Applet。

GSON is more about JSON-based persistence in the vein of XStream (which can do JSON too) and sounds a bit too heavyweight for just an Applet.

这篇关于在小程序使用GSON库时,反射的权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆