How to POST new nested objects using spring-data-rest

just wondering if POST of new objects in new entities is possible.

Person.java

@Entity
public class Person {
    @oneToOne(optional = false)
    private Address address;
}

Address.java

@Entity
public class Address {
    private String street;
}

What I would like to do is create a Person with an address in a single HTTP request. Is this possible with something like the request below?

curl -i -X POST -H "Content-Type: application/json" /
-d '{"address": {"street":"street 1"}}' http://localhost:8080/people

So far, my investigation and search for documents say no. But I thought I would ask here before I refuse.

Thank.

+4
source share
1 answer

This works, but in your example, you did not enable cascading.

@OneToOne(optional = false, cascade = CascadeType.ALL)
private Address address;

, Address. Address Person , POST.

+4

All Articles