I am trying to manipulate objects (which are JPA objects) in a Spring Data Restore API through a RestTemplate.
I have a tree structure in which Genre has parents and children of other genres (this is the itunes genre tree )
Creating an object in the order:
URI selfLink = restTemplate.postForLocation(api+"/genre", genre, Collections.emptyMap());
Creating an association with her is not so simple. If I try to establish a parent association as follows:
headers.setContentType(new MediaType("text", "uri-list")); ... restTemplate.put(selfLink.toString()+"/parent", entity, parentGenreURI );
I get an internal server 500 error on the client side, but the actual error is swallowed on the REST API side, and there is nothing in the logs.
If I try to execute PATCH the URI itself with the parent uri as follows:
headers.setContentType(MediaType.APPLICATION_JSON); ... Map map = ImmutableMap.of("parent", parentGenreLink); restTemplate.exchange(selfLink.toString()+"/parent", HttpMethod.PATCH, entity, String.class, map);
I get a 400 Bad Request error on the client, and on the server I get
org.springframework.http.converter.HttpMessageNotReadableException: Failed to read an object of type class Genre from the request !; org.springframework.http.converter.HttpMessageNotReadableException nested exception: Failed to read the payload !; nested exception com.fasterxml.jackson.databind.JsonMappingException: no content to display due to end of input
which makes me think that this is the right way to do it, but I'm just doing it wrong.
Can anyone give some recommendations on this? Every example I saw just uses curl, which doesnβt help me much :)
Somewhat similarly answered questions from SO, but most of them either point to documentation that no longer exists, or have such simple objects that all content is dumped onto the map.