GSON on Google App Engine throws a Security Exception

后端 未结 4 620
忘掉有多难
忘掉有多难 2020-12-18 00:24

I am trying to convert an object into JSON using the GSON library on Google App Engine. For some reason, it throws this exception and I don\'t understand how to solve this.

4条回答
  •  天涯浪人
    2020-12-18 01:26

    The app engine does support reflection - however you are trying to reflect on a private field of a JRE class:

    Reflection

    An application is allowed full, unrestricted, reflective access to its own classes. It may query any private members, use java.lang.reflect.AccessibleObject.setAccessible(), and read/set private members.

    An application can also also reflect on JRE and API classes, such as java.lang.String and javax.servlet.http.HttpServletRequest. However, it can only access public members of these classes, not protected or private.

    An application cannot reflect against any other classes not belonging to itself, and it can not use the setAccessible() method to circumvent these restrictions.

    ...from http://code.google.com/appengine/docs/java/runtime.html#The_Sandbox:

    I'd consider writing a custom serializer for Bitset.

    See: http://sites.google.com/site/gson/gson-user-guide#TOC-Custom-Serialization-and-Deserializ

    Also: http://groups.google.com/group/google-gson/browse_thread/thread/535892ffcf691aa/897f27e37e03ce58?lnk=gst&q=bitset#897f27e37e03ce58

    http://groups.google.com/group/google-gson/browse_thread/thread/535892ffcf691aa

提交回复
热议问题