Migrating ResourceProcessor to HATEOAS 1.0.0 M1

你离开我真会死。 提交于 2020-03-23 07:22:07

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/56118868/migrating-resourceprocessor-to-hateoas-1-0-0-m1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!