如何使用 Spring Data REST 和 HATEOAS 公开完整的树结构?

Nor*_*aft 5 tree jpa projection hateoas spring-data-rest

我有一个 JPA 树结构

@Entity
public class Document {

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private int id;
   private String text;

   @ManyToOne
   @JoinColumn(name = "parent")
   Document parent;

   @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
   Set<Document> children;

   (getters and setters)

}
Run Code Online (Sandbox Code Playgroud)

和一个投影

@Projection(name = "all", types = Document.class)
public interface AllDocumentsProjection {

    int getId();
    String getText();
    Set<Document> getChildren();

}
Run Code Online (Sandbox Code Playgroud)

当我使用 url 发出 GET 请求时

本地主机:8080/documents/1?projection=all

我只获取根文档的第一个子级。不是孩子的孩子。这可以通过投影实现吗?或者还有其他方法吗?

Nes*_*don 1

我几乎可以肯定没有办法通过投影递归地嵌入资源。我唯一想到的就是在控制器中手动处理这个逻辑:/