Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating ResourceProcessor to HATEOAS 1.0.0 M1

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?

like image 999
Sebastian Ullrich Avatar asked May 13 '19 19:05

Sebastian Ullrich


People also ask

How do I convert a spring HATEOAS model to a resource?

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.

How to update HATEOAS import statements and method references?

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.

What's new in spring HATEOAS 1?

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.

Does spring HATEOAS support client-side services?

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:


Video Answer


1 Answers

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

like image 61
Eamon Scullion Avatar answered Oct 08 '22 04:10

Eamon Scullion