spring-projects / spring-projects/spring-data-rest
Support Restemplate.getForObject(resource,MyDto[].class) on HAL +JSON [DATAREST-819]
Open
@odrotbohm is already working on this.
Since Dec 31, 2020.
in: content-negotiation
type: enhancement
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Christian Bongiorno opened DATAREST-819 and commented
Currently, to get a collection of resources that are in a HAL+JSON payload you need this code:
@Autowired
private RestOperations ops;
ResponseEntity<PagedResources<MyDto>> entity = ops.exchange(
location.expand(0, 20).getHref(), GET, null, new ParameterizedTypeReference<PagedResources<MyDto>>() {
});
PagedResources<MyDto> resources = entity.getBody();
Collection<MyDto> dtos = resources.getContent();
Which returns an immutable Collection. That's fine, but it's clunky syntax to get around Java's type erasure. Supporting this simpler approach but achieve the same effect:
@Autowired
private RestOperations ops;
MyDto[] dtos = ops.getForObject(resource,MyDto[].class);
This works fine for classic JSON arrays of data and doesn't have the ugly type erasure work around; the type of the array is easy enough to get with reflection
Affects: 2.4.4 (Gosling SR4)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.