1

Currently I am trying to migrate an API built in .NET to Java using Spring and it's related components. The only thing preventing me from completing this project is the lack of Affordances in the current release version of Spring HATEOAS (0.25.1), I am trying to replicate the data contracts as closely as I can in order to prevent breaking clients currently consuming the API.

Spring HATEOAS is included via the spring-boot-starter-hateoas Maven dependency.

I have tried the current build snapshot of the starter dependency but to no avail (the latest spring-hateos lib is not included in the starter build snapshot).

1) Is there a way to include the current milestone release into my project? If so, how do you recommend I do it.

2) If there is no way to do this, does anyone have any suggestions on how to add the Affordance concept to the current version? (Incurring some tech debt at this point is not a concern, so if you have an inelegant work around please share it, this will help me conceptually).

3) Would it be a better idea to create the HTTP return object as a HashMap and serialize it to JSON? (I understand that link of paths etc would need to be manually handled)

Other Versions: spring-boot-starter-parent: 2.1.3.RELEASE

Thanks

Kenneth Clark
  • 356
  • 1
  • 14

1 Answers1

1

Regarding question 1) Add the following dependency and do not forget that this one originates for now from the Spring Milestone Repository.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-hateoas</artifactId>
    <version>2.2.0.M1</version>
</dependency>

<repositories>
    <repository> 
        <id>repository.spring.milestone</id> 
        <name>Spring Milestone Repository</name> 
        <url>http://repo.spring.io/milestone</url> 
    </repository>
</repositories>

Alternatively you could use the whole spring-boot-starter in version 2.2.0.M1 which also contains spring-boot-starter-hateoas in 1.0.0.M1.

Question 2) should no longer concern you, question 1) seems to be easier solvable.

Regarding question 3) IMHO a strongly-typed (response-) object should almost everywhere be preferred as it makes your intentions more clear, is more easily maintainable and testable and sets you free from any worries about casting or implicit type-conversions and so on.

mle
  • 2,466
  • 1
  • 19
  • 25
  • Thanks for the feedback. I have the repo as suggested, what I meant by to "no avail" is the fact the the hateos v1 is not in the latest build snapshot of the spring-boot-starter-hateoas. I will update my question to make this clearer. I agree with point 3 but am stuck so introducing technical debt seems my only solution in order to solve this in a timely fashion. – Kenneth Clark Mar 16 '19 at 14:36
  • Ah got it, you want a current `spring-boot-starter-hateoas` in your project and not only its dependency `spring-hateoas:1.0.0.M1`, right? The latter one is already available here for you https://repo.spring.io/milestone/org/springframework/hateoas/spring-hateoas/1.0.0.M1/ I ask this just to clear things up because the subject of your question refers to `spring-hateoas` and not the starter. – mle Mar 16 '19 at 14:43
  • That is exactly it, I tried just the hateoas project and broke a stack of dependencies. I have updated the title of the question as per your suggestion, thanks. – Kenneth Clark Mar 16 '19 at 16:48
  • Thanks for the feedback. I think I now might have a Maven problem :) The 2.2.0.M1 hateoas starter has been found but it is including the hateoas 0.25.1.RELEASE. Will revert once I have more information. – Kenneth Clark Mar 16 '19 at 19:39
  • Really? Please delete all hateoas-related libraries in your local Maven repo and try again! http://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-hateoas/2.2.0.M1/spring-boot-starter-hateoas-2.2.0.M1.pom states clearly that it uses spring-hateoas 1.0.0.M1. – mle Mar 16 '19 at 19:55
  • 1
    Yeah, I did that and a maven purge etc etc. I am not sure if it is Maven or the IntelliJ IDE that is causing this confusion. Perhaps I should post a different question because as you said, the 2.2.0.M1 explicitly includes the 1.0.0.M1 version? – Kenneth Clark Mar 18 '19 at 06:45
  • 1
    I am going to mark this as the answer as it answers the original question. Will dig around in Maven and IntelliJ, if I don't come right I will post a new question. Thanks so much for your time! – Kenneth Clark Mar 18 '19 at 06:49
  • You're welcome! Keep me updated or linked if you start a new question! Have a nice week! – mle Mar 18 '19 at 07:00
  • Maven Dependency resolution question created here: https://stackoverflow.com/questions/55217926/maven-incorrect-dependancy-version-resolution – Kenneth Clark Mar 18 '19 at 09:21