Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.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 如何在子级中显示实体细节而不引起有限递归_Java_Recursion_Jackson_Spring Data - Fatal编程技术网

Java 如何在子级中显示实体细节而不引起有限递归

Java 如何在子级中显示实体细节而不引起有限递归,java,recursion,jackson,spring-data,Java,Recursion,Jackson,Spring Data,我试图从SpringRepo中获取json,但在客户端,我们需要在子级本身中包含父级详细信息 示例:(我得到的) 示例:(我想要的) 是否可以在不引起无限递归的情况下执行此操作?(最好通过注释)选项1:您可以使用 @JsonIdentityInfo(generator = PropertyGenerator.class, property = "id") 在您的汽车上和附加实体上 选项2: 使用@JsonManagedReference、@JsonBackReference @JsonMan

我试图从SpringRepo中获取json,但在客户端,我们需要在子级本身中包含父级详细信息

示例:(我得到的)

示例:(我想要的)


是否可以在不引起无限递归的情况下执行此操作?(最好通过注释)

选项1:
您可以使用

@JsonIdentityInfo(generator = PropertyGenerator.class, property = "id")
在您的
汽车上
附加实体上

选项2:
使用
@JsonManagedReference、@JsonBackReference

 @JsonManagedReference  part of reference that gets serialized normally.

 @JsonBackReference part of reference that will be omitted from serialization.
选项3:

 @JsonManagedReference  part of reference that gets serialized normally.

 @JsonBackReference part of reference that will be omitted from serialization.
您可以使用
@JsonIgnore
注释忽略关系的一方,从而打破链条


有关更多信息,我最后介绍了以下解决方法

Extras
类中:

@JsonProperty("cardetail")
public Car getCarDetail(){
    Car _car = new Car();
    // (...)Clone of the original Object, ignoring the "extras"
    return _car;
}
这几乎就是我想要的,但名字不同

@JsonProperty("cardetail")
public Car getCarDetail(){
    Car _car = new Car();
    // (...)Clone of the original Object, ignoring the "extras"
    return _car;
}