Search code examples
springspring-hateoas

Spring HATEOAS relation link encoding


I recently updated spring-hateoas from 1.3.7 to 2.2.0.

There I discovered that the query part of a link relation is now encoded. Here is the comparison:

Link in version 1.3.7

"_links": {
    "before": {
        "href": "https://localhost:8080/api/time?before=2024-03-01T06:08:07Z&itemsPerPage=10"
    }
}

Link in version 2.2.0

"_links": {
    "before": {
        "href": "http://localhost:8080/api/time?before=2024-03-01T06%3A08%3A07Z&itemsPerPage=10"
    }
}

I am creating the link like

result
  .add(
    linkTo(
      methodOn(TimeController.class).before(instant, itemsPerPage)
    )
  .withRel("before"));

When I updated, I didn't expect that this will change and it's now the case that it could possibly break API clients, since they may have encoded the URL on their end.

I tried to get into the code where the encoding happens. I saw that in org.springframework.hateoas.server.core.WebHandler at some point TemplateVariable.prepareAndEncode(Object value) is called and the values get encoded.

So I am wondering if there is a general setting that I'm missing to avoid this automatic encoding or if I have to decode it manually.

I totally understand why things are encoded now however I'd also like to see some flexibility in that case.


Solution

  • Seems to be to discussed here on github for 1.4, and is related to RFC 6570.

    Hopefully your api consumers don't reencode on their end :D