spring-projects / spring-projects/spring-hateoas

how to send entitymodel in client-side?

Open
#1,403 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

Code

        URI uri = URI.create(request.getRequestURL() + "/" + post.getId());

        HttpHeaders headers = new HttpHeaders();
        HttpEntity httpEntity = new HttpEntity(entityModel, headers);
        var returnType = new ParameterizedTypeReference<EntityModel<Post>>() {};

        RestTemplate restTemplate = new RestTemplate(Arrays.asList(new MappingJackson2HttpMessageConverter()));
        restTemplate.setMessageConverters(Traverson.getDefaultMessageConverters(MediaTypes.HAL_JSON));
        var result = restTemplate.exchange(uri, HttpMethod.PUT, httpEntity, returnType);

Error
org.springframework.web.client.RestClientException: No HttpMessageConverter for org.springframework.hateoas.EntityModel
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:961) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:737) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:714) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:632) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the RestTemplate.exchange call and the MappingJackson2HttpMessageConverter and Traverson.getDefaultMessageConverters setup shown in the report. Reproduce the No HttpMessageConverter exception using the EntityModel request body, then determine what configuration or supported request representation is expected. Done means the client can send the EntityModel without the reported RestClientException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.