'Does Spring rest have an built-in finder of existing Entity in request?

Does Spring rest have an built-in finder of existing Entity in request body? For example, i have entity:

@Entity
@Table(name = "category")
@NoArgsConstructor
public class Category {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JsonIgnore
    private Integer id;

    @Column
    private String name;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "user_id")
    private User user;
}

How to make a Controller, which will be parse this json body (maybe change "user" value on reference?), create a new Category and put existing User with id=1 (which exists in the table)?

Post: localhost:8080/api/categories
json body: {
    "name": "Food",
    "user": 1
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source