Consuming HAL-based REST service with spring-hateoas

前端 未结 4 1346
一生所求
一生所求 2021-01-14 22:02

I\'m trying to consume a HAL-based REST service with the RestTemplate class. The response body looks like this:

{
  \"_embedded\": {
    \"school:teachers\":         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-14 22:36

    Definitely, you should go with Traverson

    Traverson client = new Traverson(new URI("http://localhost:8080/api/"), 
             MediaTypes.HAL_JSON);
        Resources> teachers = client
            .follow("school:teachers")
            .toObject(new ResourcesType>(){});
    

    https://docs.spring.io/spring-hateoas/docs/current/reference/html/#client.traverson

提交回复
热议问题