spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
913 stars 561 forks source link

AggregateReference bug #2323

Open jacko9et opened 11 months ago

jacko9et commented 11 months ago

Referring to the usage method of the document:

  @GetMapping(path = "/scanners")
  ResponseEntity<?> getProducers(
    @RequestParam AggregateReference<Producer, ProducerIdentifier> producer) {

    var identifier = producer.resolveRequiredId();
    // Alternatively
    var aggregate = producer.resolveRequiredAggregate();
  }

The following information is returned:

Source to convert from must be an instance of [java.lang.String]; instead it was a [java.net.URI]

mp911de commented 11 months ago

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

jacko9et commented 11 months ago

I've created a minimal example to reproduce the issue. https://github.com/jacko9et/spring-data-rest-demo

odrotbohm commented 10 months ago

There is no support for resolving a URI to an AggregateReference instance yet. Any reason you're not simply declaring the Producer as parameter type?

An already fully supported alternative to AggregateReference is jMolecules' Association which is essentially the same as AR, independent of Spring Data, but fully supported through automatically registered converters via the org.jmolecules.integrations:jmolecules-spring artifact.

jacko9et commented 10 months ago

@odrotbohm Thank you for your reply. I would like the custom controller's parameters to be able to resolve the uri to the entity to comply with hateoas usage, but it cannot be resolved automatically. I tried adding the annotation @Param or @RequestParam to the entity type, but it didn't work. Is there any arbitrary way to parse uri to entities?