1

I am following this tutorial: Spring HATEOAS - Basic Example

And I have a spring boot project with the following dependencies:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-data-rest</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.9.0</version>
    </dependency>
</dependencies>

The tutorial shows that Spring HATEOAS provides SimpleIdentifiableResourceAssembler as the simplest mechanism to perform conversions.

The problem is that I cannot resolve the class "SimpleIdentifiableResourceAssembler" from the org.springframework.hateoas packages .. It throws an SimpleIdentifiableResourceAssembler cannot be resolved to a type

Manuel
  • 205
  • 1
  • 4
  • 17

4 Answers4

3

Even though it's sort of late but for future (and confused) developers: The answer is simply that the Class

SimpleIdentifiableResourceAssembler

has not been added to the Repo so far. You have to implement the functionality on your own (see Github issue for this question)

Vetemi
  • 784
  • 2
  • 9
  • 26
1

HATEOAS dependency is added in:

enter image description here

But this does not solve the problem

Manuel
  • 205
  • 1
  • 4
  • 17
0

You don't have the HATEOAS dependency in your project.

Add

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-hateoas</artifactId>
    </dependency>
Darren Forsythe
  • 10,712
  • 4
  • 43
  • 54
0

In my project, I use RepresentationModelAssembler it is part of

org.springframework.hateoas.server.RepresentationModelAssembler;

example:

@Component
public class AccountModelAssembler implements RepresentationModelAssembler<AccountResponse, EntityModel<AccountResponse>> {

  @Override
  public @NonNull CollectionModel<EntityModel<AccountResponse>> toCollectionModel(@NonNull Iterable<? extends AccountResponse> entities) {
    return RepresentationModelAssembler.super.toCollectionModel(entities);
  }

  
  @Override
  public @NonNull EntityModel<AccountResponse> toModel(@NonNull AccountResponse entity) {
    // Do your mapping and link generation here.
  }
}

And AccountResponse is like this:

@JsonInclude(JsonInclude.Include.NON_NULL)
public record AccountResponse(
    Integer id,
    String code,
    String name,
    String description,
    AccountTypeEnum type
) {
}
DharmanBot
  • 1,066
  • 2
  • 6
  • 10
Mohamed Taman
  • 95
  • 1
  • 6