【问题标题】:is there any open source project for Restlet on GAE available?是否有任何可用的 GAE 上 Restlet 的开源项目?
【发布时间】:2011-05-30 14:40:03
【问题描述】:
我正在寻找托管在 GAE 上的 Restlet 的开源项目,并试图通过 restlet + objectify 找出 CRUD 操作。在我当前的应用程序中,我使用了以下内容,
- 使用 Restlet 实现完整的 web 服务
- 对象化为 ORM 框架。
- 在 GAE 上托管。
我不太清楚如何在 restlet 中使用 JSON 表示来请求响应。
因此,如果有开源项目在 google 代码或 github 上进行,它会有所帮助。
谢谢
【问题讨论】:
标签:
java
google-app-engine
orm
restlet
objectify
【解决方案2】:
我在一个项目中使用相同的技术。如果您正在寻找 JSON 表示示例,下面的代码可能会有所帮助。我正在使用Gson 处理 JSON 序列化/反序列化:
public Foo() {
private String name;
public Foo() {};
public Foo(String name) {
this.name = name;
}
public String toJson() {
return new Gson().toJson(this);
}
}
@Get("json")
public Representation represent() {
Foo foo = new Foo("bar");
return new JsonRepresentation(foo.toJson());
}
@Post("json")
public Representation post(Representation entity) {
JsonRepresentation json = null;
try {
json = new JsonRepresentation(entity);
Gson gson = new Gson();
Foo foo = gson.fromJson(json.getText(), Foo.class);
} catch (Exception e) {
System.err.println(e.getMessage());
}
return json;
}