【问题标题】:RESTlet tutorial application does not return Java Objects (JSON only)RESTlet 教程应用程序不返回 Java 对象(仅限 JSON)
【发布时间】:2011-05-10 03:06:30
【问题描述】:

我一直在寻找来自 Restlet official tutorial 的源代码。

我正在尝试使用教程中的 Android 应用程序访问 Restlet 服务器,我只得到 JSON 响应,而不是 Java 对象。我尝试使用所有库和扩展,没有任何效果。当我点击教程网址(http://restlet-example-serialization.appspot.com/contacts/123)时,我得到了所需的响应。有任何想法吗?顺便说一句,我只是在示例中使用服务器 (GAE),而不是 GWT 前端。

【问题讨论】:

  • 此外,Java SE 客户端工作正常。只是 Android 客户端不工作。

标签: android google-app-engine restlet-2.0


【解决方案1】:

使用 GSOn 将 json 转换为 java 对象。您可以从 google 获得 GSON 作为其代码:

http://code.google.com/p/google-gson/

其他方式:

Response res = client.handle(req); 
    ObjectRepresentation<Item> obj = new ObjectRepresentation<Item>(res.getEntity()); 
    Item item = obj.getObject(); 

【讨论】:

  • 我不想那样做。从理论上讲,Restlet 的美妙之处在于您只处理 Java 对象,而不必序列化/反序列化。还有其他想法吗?
  • 另一种方式是:响应 res = client.handle(req); ObjectRepresentation obj = new ObjectRepresentation(res.getEntity());项目 item = obj.getObject();
  • 所以在Android客户端,教程中有这么一段代码:contact = resource.retrieve();其中contact 是Contact 类型,Resource 是ContactServerResource 类型。您的代码如何替换它?为什么当我访问 estlet-example-serialization 应用程序时这段代码可以工作,但当我在 GAE 中我的应用程序下部署代码时却不行?
猜你喜欢
  • 2011-04-07
  • 1970-01-01
  • 2018-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多