Search code examples
javaspringspring-hateoashateoas

What should I use instead of deprecated CollectionModel?


Spring documentation tells me here: https://docs.spring.io/spring-hateoas/docs/1.2.2/reference/html/#migrate-to-1.0.changes.representation-models that I should use CollectionModel instead of Resources class. But when I do, my IDE tells me that CollectionModel is deprecated. Like here:

enter image description here

What should I do now or use now to achieve HATEOAS in Spring boot?


Solution

  • Only the constructor is deprecated. Instead you should use the static method from CollectionModel public static <T> CollectionModel<T> of(Iterable<T> content,Iterable<Link> links)

    Further informations are here: https://docs.spring.io/spring-hateoas/docs/current/api/org/springframework/hateoas/CollectionModel.html#CollectionModel-java.lang.Iterable-org.springframework.hateoas.Link...-