Answer the question
In order to leave comments, you need to log in
How to deserialize an object received from a Spring Data Rest service?
Spring Data Rest returns HATEOAS JSON, respectively, references to internal objects are passed by links:
public class Filial {
private long id;
private String name;
}
public class User {
private long id;
private String name;
@JoinColumn(...)
private Filial filial;
}
{
"_embedded": {
"users": [
{
"id": 1,
"name": "test1",
"_links": {
"self": {
"href": "http://localhost/users/1"
}
"filial": {
"href": "http://localhost/users/1/filial"
}
}
}
]
}
"_links": { ... },
"page": { ... }
}
@FeignClient(url = "http://localhost/", name = "user-client")
public interface UserClient {
@RequestMapping(method = GET, value = "/users")
Resources<User> getAll();
}
Answer the question
In order to leave comments, you need to log in
The docs say to use @Projection
. But for some reason it only works if excerptProjection is explicitly specified in the
docs.spring.io/spring-data/rest/docs/current/refer...
So, that's the point of REST/HATEOAS - you don't get the associated object, just a link to it. Those. after receiving the user, you need to get a branch using the link from _links.filial.
If this approach does not suit you, then you can implement your own behavior of the REST service.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question