プロジェクトで同じテクノロジーを使用しています。JSON 表現の例を探している場合は、以下のコードが役立つ場合があります。JSONのシリアライゼーション/デシリアライゼーションを処理するためにGsonを使用しています:
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;
}