最后,我找到了一种更好的使用这些application / hal + json API的方法。
实际上,Spring hateoas提供了几乎可以使用的客户端:org.springframework.hateoas.client.Traverson。
Traverson traverson = new Traverson(new URI("http://localhost:8080/test"), MediaTypes.HAL_JSON);TraversalBuilder tb = traverson.follow("users");ParameterizedTypeReference<Resources<UserJson>> typeRefDevices = new ParameterizedTypeReference<Resources<UserJson>>() {};Resources<UserJson> resUsers = tb.toObject(typeRefDevices);Collection<UserJson> users= resUsers .getContent();如您所见,我摆脱了UsersJson和UsersEmbeddedListJson。
这是我添加的Maven依赖项
<dependency> <groupId>org.springframework.hateoas</groupId> <artifactId>spring-hateoas</artifactId> <version>0.19.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.plugin</groupId> <artifactId>spring-plugin-core</artifactId> <version>1.2.0.RELEASE</version> </dependency> <dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <version>2.0.0</version> </dependency>



