Skip to content
Advertisement

Return link from Hateos

I have this old Spring Hateos code which I want to migrate to the latest version:

JavaScript

I tried this:

JavaScript

I get error at this line:

JavaScript

Can you advise what is the correct way to implement this?

Advertisement

Answer

Based on your comments & question for migration this is what I am suggesting:

JavaScript

….

//calling addLinlk

JavaScript

And inside addLink:

JavaScript

Tested with Java 11 & spring-hateoas 1.5.0. If you have any different versions, please let me know.

Edit

As per OP mentioned, they are using hateoas version 2.6.7. The response reference in OP’s code is custom class which extending RepresentationModel. So response.getLink(..) will return type of Optional<Link>. So below workaround will work :

JavaScript

No changes in addLink & no changes in calling addLink required, my original answer still valid for other operations.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement