카테고리 없음
[Spring] JsonProperty
happyst
2024. 8. 9. 15:11
Jackson 라이브러리의 JsonProperty 어노테이션을 이용하여 JSON 데이터와 Java 클래스의 필드를 맵핑 시켜줄 수 있다.
사용법
import com.fasterxml.jackson.annotation.JsonProperty;
예시
import com.fasterxml.jackson.annotation.JsonProperty;
public class DocumentDto {
@JsonProperty("place_name")
private String placeName;
@JsonProperty("address_name")
private String addressName;
@JsonProperty("y")
private double latitude;
@JsonProperty("x")
private double longitude;
@JsonProperty("distance")
private double distance;
}
설명
위 예시에서, JSON 데이터의 key place_name은 자바 클래스의 필드 placeName과 맵핑된다.