Google端点消息对象是非常简单的POJO。我有一个曾经工作过的复合POJO,但现在不再工作了。当Android客户端进行调用时,我收到的错误是由于AnimalTag而无法解析JSON。这是POJO。为了迁移到Java 7,我手动复制并粘贴了代码。所以我认为这可能是原因,也许我遗漏了一些东西。但是我想不出是什么问题。其他通话正常。但是,这一直失败。

用法是该方法从客户端接收Dog以保存在服务器上。并非Dog中的所有数据都已填充,但包括AnimalTag在内的许多数据都已填充。此外,AnimalTag只填充制造商。再次,这一切都起作用。

public class Dog {

    private String name;
    private String owner;
    private AnimalTag tag;

    public Dog(String name, String owner, AnimalTag tag) {
      super();
      this.name = name;
      this.owner = owner;
      this.tag = tag;
  }

    public String getName() {
        return this.name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getOwner() {
        return this.owner;
    }
    public void setOwner(String owner) {
        this.owner = owner;
    }
    public AnimalTag getTag() {
        return this.tag;
    }
    public void setTag(AnimalTag tag) {
        this.tag = tag;
    }

}


class AnimalTag{
    private long number;
    BlobKey imageKey;
    String manufacturer;

    public AnimalTag(long number, BlobKey imageKey, String manufacturer) {
      super();
      this.number = number;
      this.imageKey = imageKey;
      this.manufacturer = manufacturer;
  }

    public long getNumber() {
        return this.number;
    }
    public void setNumber(long number) {
        this.number = number;
    }
    public BlobKey getImageKey() {
        return this.imageKey;
    }
    public void setImageKey(BlobKey imageKey) {
        this.imageKey = imageKey;
    }
    public String getManufacturer() {
        return this.manufacturer;
    }
    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }
}

最佳答案

我得到了答案,AnimalTag缺少以下构造函数:

public AnimalTag(){}

08-06 10:07