Hypermedia AThe Engine OApplication State

의존성 추가

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

ObjectMapper와 LinkDiscovers 제공

테스트 코드

@RunWith(SpringRunner.class)
@WebMvcTest(SampleController.class)
public class SampleControllerTest {

	@Autowired
	MockMvc mockMvc;

	@Test
	public void hello() throws Exception {
		mockMvc.perform(get("/hello"))
				.andDo(print())
				.andExpect(status().isOk())
				.andExpect(jsonPath("$._links.self").exists());
	}
}

컨트롤러

@RestController
public class SampleController {

	@GetMapping("/hello")
	public Resource<Hello> hello() {
		Hello hello = new Hello();
		hello.setPrefix("Hey,");
		hello.setName("cmlee");

		Resource<Hello> helloResource = new Resource<>(hello);
		helloResource.add(linkTo(methodOn(SampleController.class).hello()).withSelfRel());

		return helloResource;
	}
}

ObjectMapper 제공

LinkDiscovers 제공