Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 泽西Json列表<;列表<;实体>&燃气轮机;连载_Java_Json_Rest_Jersey_Jackson - Fatal编程技术网

Java 泽西Json列表<;列表<;实体>&燃气轮机;连载

Java 泽西Json列表<;列表<;实体>&燃气轮机;连载,java,json,rest,jersey,jackson,Java,Json,Rest,Jersey,Jackson,我有以下问题: 我有一个用Java编写的json rest服务。我想返回一个包含列表的实体。此列表还包括一个列表。当我调用rest服务时,我得到了正确的第一个元素,但是从另一个元素只得到了id 有人能帮我吗 以下是一些代码片段: @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property = "@Entity") public class Entity { private Long id;

我有以下问题:

我有一个用Java编写的json rest服务。我想返回一个包含列表的实体。此列表还包括一个列表。当我调用rest服务时,我得到了正确的第一个元素,但是从另一个元素只得到了id

有人能帮我吗

以下是一些代码片段:

@JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property = "@Entity")
public class Entity {

    private Long id;

    private List<List<Parent>> possibleParents = new ArrayList<List<Parent>>();

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<List<Parent>> getPossibleParents() {
        return possibleParents;
    }

    public void setPossibleParents(List<List<Parent>> possibleParents) {
        this.possibleParents = possibleParents;
    }

}


@JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property = "@Parent")
public class Parent {

    private Long id;

    private String parentType;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getParentType() {
        return parentType;
    }

    public void setParentType(String parentType) {
        this.parentType = parentType;
    }
}
下面是我得到的:

{
   "@Entity": "ef0ecdbf-c354-4646-8ef0-d4794b3e7919",
   "id": "1",
   "possibleParents": [
    [{ "@Parent": "easecdbf-c354-4646-8ef0-d4794b3e7919",
       "id": "1", "parentType": "Test"
        }, 
        "5c0c708e-0c23-4432-954f-20f42909067f", 
        "a2a644d4-3068-4662-b95a-d313d896b17f"
        ]
    ]
}
预期:

{ "@Entity": "ef0ecdbf-c354-4646-8ef0-d4794b3e7919", 
  "id": "1", 
  "possibleParents": [ 
     [{"@Parent": "easecdbf-c354-4646-8ef0-d4794b3e7919",
        "id": "1", "parentType": "Test" }, 
      {"@Parent": "5c0c708e-0c23-4432-954f-20f42909067f",
       "id": "2", "parentType": "Test2" }, 
      {"@Parent": "a2a644d4-3068-4662-b95a-d313d896b17f",,
       "id": "3", "parentType": "Test3" } 
     ] 
   ] 
}

我不确定你是否向我们展示了所有的代码,或者考虑到可能是正确的代码,租金应该是财产而不是父母。我猜你的父母列表是一个异构的对象列表。在控制器中放置调试断点或注销父列表的内容。存在多个可能的父组合。所以我可以在possibleParents列表中有两个父列表。我们发现Jackson序列化程序不能处理某些结构,所以我们开始使用Gson,我必须考虑一下。但我希望任何人都能为我的问题找到解决方案。看来这个对象以前已经序列化过了。有没有可能说是整个对象而不仅仅是id?
{ "@Entity": "ef0ecdbf-c354-4646-8ef0-d4794b3e7919", 
  "id": "1", 
  "possibleParents": [ 
     [{"@Parent": "easecdbf-c354-4646-8ef0-d4794b3e7919",
        "id": "1", "parentType": "Test" }, 
      {"@Parent": "5c0c708e-0c23-4432-954f-20f42909067f",
       "id": "2", "parentType": "Test2" }, 
      {"@Parent": "a2a644d4-3068-4662-b95a-d313d896b17f",,
       "id": "3", "parentType": "Test3" } 
     ] 
   ] 
}