POJO to an XML string in Google App Engine?

2019-07-22 16:49发布

I would like to create a REST interface for my Java Google App Engine program. I figured I would start by generating some XML from my POJOS. However, it seems that XStream is bitten by GAE's restrictions.

What can I use to generate an XML string in Google App Engine?

Thanks.

Edit 1: Here is the beginning of the exception:

javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract    java.lang.String com.mydomain.client.ObjectService.sendObject(com.mydomain.client.models.myobject)' threw an unexpected exception: java.security.AccessControlException: access denied (java.io.SerializablePermission enableSubclassImplementation)

3条回答
仙女界的扛把子
2楼-- · 2019-07-22 17:29

For the same restriction (a patch is underway however) I ended producing JSON using org.json library. Also JAXB seems not to be in the whitelist.

查看更多
倾城 Initia
3楼-- · 2019-07-22 17:41

The exception is caused by a java.io.SerializablePermission, which according the javadoc is for allowing:

Subclass implementation of ObjectOutputStream or ObjectInputStream to override the default serialization or deserialization, respectively, of objects

XStream might be using Object streams under the covers, and falling foul of this permission not being granted.

Does Google App Engine actually have a whitelist, or just a set of restricted permissions? JAXB2 doesn't use Object streams, so have you actually tried that?

查看更多
叛逆
4楼-- · 2019-07-22 17:47

Try Jersey - it will give you XML, JSON, and lots more via REST; all using annotated methods.

It works for me, however there are some caveats:

See here and here

查看更多
登录 后发表回答