在Google Cloud Endpoints中如何返回动态Json

时间:2013-07-16 21:51:08

标签: google-app-engine google-cloud-endpoints

我希望从我的端点返回一个动态JSON对象,以便在不改变任何方法签名的情况下即时添加属性。

1 个答案:

答案 0 :(得分:1)

感觉与端点的设计相反,但我发现拥有可以接受或返回任意JSON对象的端点非常有用。所以我在我的端点方法中使用这样的类:

public class DataParcel {
  public Integer obj_type = -1;
  public List<String> json_objects = null;  // new ArrayList<String>();

唯一的复杂因素是使用哪个JSON库 - 不再为您自动完成JSON编码/解码。