Skip to content

"links" used instead of "_links" when response contains a list of resource items #709

Closed
@jhoweaa

Description

@jhoweaa

I'm using Spring Boot 2.0 with Spring Boot HATEOAS 0.24.0.RELEASE and I'm seeing an inconsistency with the way my links are appearing when resources are rendered to JSON. If I return a single instance of Resource<Document> (where Document is a class we wrote), I will see something like this:

{
   "name": "some name",
   "format": "pdf",
   ...
   "_links": {
      "self" : {
          "href": "..."
      }
   }
}

This is from a method in my @RestController which is defined like this:

@RequestMapping(value = "/accessory", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public Resource<Document> getTestDocument() throws IOException, ReportServiceException {
    ...
}

however, if I return a list of Resource<Document> like this:

@RequestMapping(value = "/accessories", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public java.util.List<Resource<Document>> getAvailableDocuments() throws IOException, ReportServiceException {
  ...
}

I get results that look like this:

[
  {
    "name": "some name",
    "format": "pdf",
    "links": [
      {
        "rel": "self",
        "href": "..."
      }
      ...
  },
  ...
]

The only difference between the two is that in one case I'm returning a list of resources, and the other I'm just returning a single instance of the resource. Seems like a bug, but perhaps I'm just not setting something up correctly?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions