I use crnk (JSON-API) in java project and I have 3 questions regarding its usage with spring boot and jpa - haven't found exact implementation details in documentation.
For example, I have 2 entities and respective tables:
@Entity @JsonApiResource(type = "employee") public class Employee { @Id @JsonApiId private int id; private String name; @ManyToOne @JoinColumn(name = "typeId") private EmployeeType employeeType; //stored in table as typeId } @Entity @JsonApiResource(type = "type") public class EmployeeType { @Id @JsonApiId private int id; private String typeName; private int salary; }
How should JsonApiRelation be introduced in order to be able to call "/employee/1" and "/employee/1/type" urls?
For example there is one more entity.
@Entity @JsonApiResource(type = "project") public class Project { @Id @JsonApiId private int id; private String supervisorName; private String projectName; }
First, I'd like to have List of Projects for each Employee, where he is a supervisor, joint by name and have it listed as attribute in Json.
Tried implementing it with @OneToMany and @JoinColumn annotations but got StackOverflowException. How could this be implemented. And second, how could this be implemented with Relation? Like "/employee/1/projects" url.
- How should I implement custom filtering of results for findAll method? For example, I have a List of all Employees, but I'd like to exclude some of them from the response. Which class/method should be introduced for this behaviour?