ObjectMapper

Jackson 라이브러리에서 JSON과 Java 객체 간의 직렬화·역직렬화를 수행하는 핵심 클래스입니다.

핵심 특징

주요 사용 예시

ObjectMapper mapper = new ObjectMapper();

// JSON → 객체 (역직렬화)
String json = "{\"name\":\"Alice\",\"age\":30}";
Person person = mapper.readValue(json, Person.class);

// 객체 → JSON (직렬화)
String result = mapper.writeValueAsString(person);

핵심 정리

ObjectMapper는 HttpMessageConverter와 함께 Spring REST API에서 JSON 요청/응답을 Java 객체로 자동 변환합니다.

CSLOG에서 보기