I have a project that deals with some ORM object mapping (there are some @OneToMany relationships, etc.).
I use the REST interface to handle these objects and Spring JPA to manage them in the API.
This is an example of one of my POJOs:
@Entity public class Flight { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; private String name; private String dateOfDeparture; private double distance; private double price; private int seats; @ManyToOne(fetch = FetchType.EAGER) private Destination fromDestination; @ManyToOne(fetch = FetchType.EAGER) private Destination toDestination; @OneToMany(fetch = FetchType.EAGER, mappedBy = "flight") private List<Reservation> reservations; }
When executing the request, I must specify everything in JSON:
{ "id": 0, "reservations": [ {} ], "name": "string", "dateOfDeparture": "string", "distance": 0, "price": 0, "seats": 0, "from": { "id": 0, "name": "string" }, "to": { "id": 0, "name": "string" } }
What would I prefer, it actually indicates the identifier of the reference object instead of all its bodies, for example:
{ "id": 0, "reservations": [ {} ], "name": "string", "dateOfDeparture": "string", "distance": 0, "price": 0, "seats": 0, "from": 1, "to": 2 }
Is it possible? Can someone give me some idea on how to do this? I only find tutorials on how to do the opposite (the solution that I already have).