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

Custom ResourceProcessor is not called for an empty Resources [DATAREST-462]

Open
#841 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Bert Duerinck opened DATAREST-462 and commented

I want to add links to a Collection Resources object even when the collection Resource is empty.

The following class is created for doing this:

@Component
public class OrderResourcesProcessor implements ResourceProcessor<Resources<Resource<Order>>> {
	@Autowired
	private EntityLinks entityLinks;

	@Override
	public Resources<Resource<Order>> process(Resources<Resource<Order>> resources) {
		resources.add(entityLinks.linkFor(Order.class).withRel("createOrder"));
		resources.add(entityLinks.linkFor(Order.class).withSelfRel());

		return resources;
	}
}

This ResourceProcessor is called when my Order collection Resource is not empty, but it's not called when it's empty. I should also have the possibility to add links when the collection is empty. According to the HAL specification, at least the self rel should be available in a resource, even if the resource is empty


Affects: 2.2.1 (Evans SR1)

1 votes, 4 watchers

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.