spring-projects / spring-projects/spring-data-rest

Document how to use TestRestTemplate with spring-data-rest

Open
#2,365 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Feb 20, 2024.

status: waiting-for-triage
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

TestRestTemplate is relatively popular in the spring world but it's not obvious how to use it with the spring-data-rest CrudRepository generated endpoints. spring-data-rest wraps every response in an object I didn't create. It's not obvious how to use TestRestTemplate with this object unless I return simple response classes like String or Map<?, ?>.

    • If TestRestTemplate can be used with spring-data-rest, please provide examples of using it with response bodies more complex than String or Map<?, ?>. e.g., a Person class.
    • Please also include a postForEntity and/or putForEntity(putForEntity doesn't exist) example, because I see a lot of people struggling to make requests that send a complex class, e.g., Person, in the request body.
    • If TestRestTemplate is the wrong tool for the job, please recommend the right tool or a better tool. This might already be documented, but I've been unable to find it.

Thanks,
Dan

Contributor guide

Open the contributing guide

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.