In my current Spring HATEOAS 0.25.1.RELEASE project I make heavy use of ResourceProcessor interfaces:
@Bean
public ResourceProcessor<Resource<Person>> personProcessor() {
return new ResourceProcessor<Resource<Person>>() {
@Override
public Resource<Person> process(Resource<Person> resource) {
resource.add(new Link("http://localhost:8080/people", "added-link"));
return resource;
}
};
}
How can can I migrate my ResourceProcessors to Spring HATEOAS 1.0.0 M1?
The conversion contains very custom steps but also a few boilerplate steps: Adding a link with a rel of self pointing to the resource that gets rendered. Spring HATEOAS now provides a RepresentationModelAssemblerSupport base class that helps reduce the amount of code you need to write.
You can find a script to run from your application root that will update all import statements and static method references to Spring HATEOAS types that moved in our source code repository. Simply download that, run it from your project root.
1.1.1. The changes The biggest changes in package structure were driven by the introduction of a hypermedia type registration API to support additional media types in Spring HATEOAS. This lead to the clear separation of client and server APIs (packages named respectively) as well as media type implementations in the package mediatype.
This section describes Spring HATEOAS’s support for clients. 6.1. Traverson Spring HATEOAS provides an API for client-side service traversal. It is inspired by the Traverson JavaScript library . The following example shows how to use it:
In Spring HATEOAS 1.0 M1, a lot of types and APIs have changed naming conventions.
In your example ResourceProcessor
is now RepresentationModelProcessor
, and Resource<T>
is now EntityModel<T>
, like so:
public RepresentationModelProcessor<EntityModel<Person>> personProcessor() {
return new RepresentationModelProcessor<EntityModel<Person>>() {
@Override
public EntityModel<Person> process(EntityModel<Person> entityModel) {
entityModel.add(new Link("http://localhost:8080/people", "added-link"));
return entityModel;
}
};
}
See the full change notes here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With