Skip to content

Access HAL+JSON-_compatible_ resources that have a custom media type using Traverson #1050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mkhl opened this issue Aug 11, 2019 · 2 comments

Comments

@mkhl
Copy link

mkhl commented Aug 11, 2019

I'm using Spring 5.1.8, Spring Boot 2.1.6, and Spring HATEOAS 0.25.1.

As an example, I want to access Spring Boot Actuator resources, which are transmitted with the media type application/vnd.spring-boot.actuator.v2+json.

For that to work, I have to provide a LinkDiscoverer for that media type:

    @Bean
    LinkDiscoverer actuatorLinkDiscoverer() {
        var halJsonPathTemplate = "$._links..['%s']..href"; // stolen from HalLinkDiscoverer
        return new JsonPathLinkDiscoverer(halJsonPathTemplate, parseMediaType(ActuatorMediaType.V2_JSON));
    }

The definition is basically a copy of HalLinkDiscoverer since I cannot create instances of that with a custom media type, or access the JSON Path template.

It would be nice if creating LinkDiscoverers for HAL+JSON-compatible media types were easier.

@gregturn
Copy link
Contributor

Since new efforts target Spring Boot 2.2, I’ve created #1052 to focus on smoothing the connection between these two.

I need to review Spring Boot’s usage of hypermedia to ensure they are doing things properly as well so the whole experience makes sense.

@mkhl
Copy link
Author

mkhl commented Aug 12, 2019

That's great to hear!

Since Actuator is just an example, I assume the way to support other media types is as described in https://docs.spring.io/spring-hateoas/docs/1.0.0.RC1/reference/html/#mediatypes.custom, and possibly by extending HalMediaTypeConfiguration if the type is compatible with HAL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants