I have a Foo class and a Bar class:
@Entity
public class Foo extends BaseEntity {
private Long id;
private String foo;
}
@Entity
public class Bar extends BaseEntity{
private Long id;
private String bar;
}
And a @Controller
@Controller
...
@RequestMapping(value = "/foo/{foo}")
public void foo(@PathVariable("foo") Foo foo) {
...
With Spring Data JPA and Sprint REST, I'm able to pass e.g. Foo as an id in the URL and automatically get a Foo object via the built-in domain-class-converter http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web.basic.domain-class-converter:
This works fine. But in some cases I want to POST data to the controller via JSON instead of url parameter
{
foo : {id : 42},
bar : {id : 123},
}
Is it possible to automatically get that similarly completely loaded from JPA (and not only initialized with the id)?
I tried @RequestBody but that only initializes the values that are given by the request without loading the entity from the db.