Search code examples
springspring-bootspring-mvcspring-hateoas

spring hateoas 1.1.0 base rel path getting truncated


I have recently upgraded our application into Spring Boot 2.3.2.RELEASE which uses Spring Hateoas 1.1.0.RELEASE.

My base rel path for any link is: "urn:eim:linkrel:"

With Spring Boot 2.2.6.RELEASE, the response is like below:

{
    "_links": {
        "urn:eim:linkrel:users": {
            "href": "https://localhost:8080/v1/users"
        }
    }
}

With Spring Boot 2.3.2.RELEASE, the response changed like below:

{
    "_links": {
        "urn:eim": {
            "href": "https://localhost:8080/v1/users"
        }
    }
}

My code to generate the above response:

import javax.servlet.http.HttpServletRequest;

import org.springframework.hateoas.Link;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {

    @RequestMapping(value = "/service", method = RequestMethod.GET, produces = "application/hal+json")
    public HttpEntity<RepresentationModel<?>> service(HttpServletRequest request) {
        
        RepresentationModel<?> service = new RepresentationModel<>();

        service.add(Link.of("https://localhost:8080/v1/users", "urn:eim:linkrel:users"));

        return new ResponseEntity<>(service, HttpStatus.OK);
    }
}

Does anyone has similar issue? Can anyone please let me know the solution to fix this issue.


Solution

  • According to Github issue, this issue (support multiple colons) is fixed and is going to be release in milestone 1.2.0-M1.

    I see the fix commit is in branch 1.1.x. I guess the fix may be included in fix version 1.1.1.