0

https://www.crnk.io/releases/stable/documentation/#_jsonapirelation

What is the need of @JsonApiRelationId as I see no difference without using it?

1 Answers1

1

You can use @JsonApiRelationId instead of @JsonApiRelation when you just need to perate on ID, not on the entire related resource, or when the id of related resource can be obtain much cheaper then full resource.

Both could look like this:

public class Car {
  ...

  @JsonApiRelationId
  private Long ownerId;

  @JsonApiRelation
  private Person owner;
dgebert
  • 1,235
  • 1
  • 13
  • 30
  • as per documentations "JsonApiRelationId fields are used for: GET requests to fill-in the data section of a relationship. POST and PATCH requests to fill-in the new value without having to fetch and set the entire related resource." I tried to use JsonApiRelationId but did not see any data section. Also please let me know how can I use JsonApiRelationId in ManyToMany relationships. – vishal jagdale Mar 15 '20 at 06:48
  • You can populate the data of child object(and see the data section) only with `@JsonApiRelation` . You should use the Id reference only when the child object already exists in your db, and you just want add the relationship, not the child object data. – dgebert Mar 15 '20 at 17:51