@GetMapping(value = "/cafe-info", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<CafeInfoResponse> getCafeInfo() {
return ResponseEntity.ok(new CafeInfoResponse());
}
public class CafeInfoResponse {
private int cafeSeq;
}
@Getter
@Setter
public class CafeInfoResponse {
private int cafeSeq;
}
getter를 추가해주면 된다.
@Test
void test(){
var objectMapper = Jackson2ObjectMapperBuilder.json().build();
Assertions.assertTrue(objectMapper.isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
Assertions.assertTrue(objectMapper.isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
//objectMapper.getVisibilityChecker() 통해서도 확인 가능
}
참고자료
https://spring.io/guides/gs/rest-service/
https://fasterxml.github.io/jackson-databind/javadoc/2.10/com/fasterxml/jackson/databind/MapperFeature.html#AUTO_DETECT_GETTERS
https://fasterxml.github.io/jackson-databind/javadoc/2.10/com/fasterxml/jackson/databind/MapperFeature.html