-
FAIL_ON_UNKNOWN_PROPERTIES = false (관용 모드, Spring Boot 기본값)자바 및 spring boot 2026. 4. 20. 13:37
Jackson 역직렬화 — 알 수 없는 필드 처리
기본 동작
FE에서 이런 JSON을 보냈다고 가정:
{ "campaignId": 222139, "payType": "card", "bill": { "fundingAmount": 10000 }, "attributes": { "addDonation": 1000, "dontShowNameYn": "Y" } }서버 DTO에 attributes 필드가 없을 때:
FAIL_ON_UNKNOWN_PROPERTIES = true (엄격 모드)
// 400 Bad Request 발생 // "Unrecognized field 'attributes'"DTO에 없는 필드가 하나라도 있으면 에러로 처리합니다.
FAIL_ON_UNKNOWN_PROPERTIES = false (관용 모드, Spring Boot 기본값)
// 정상 200 OK // 'attributes' 필드는 조용히 무시됨 // DTO에 있는 campaignId, payType, bill만 매핑됨DTO에 없는 필드는 에러 없이 버려집니다.
설정 위치
1. Spring Boot 자동 설정 (전역)
# application.yml spring: jackson: deserialization: fail-on-unknown-properties: false # Spring Boot 기본값Spring Boot는 이 값을 기본 false로 세팅합니다. 명시적으로 true로 바꾸지 않는 한 관용 모드입니다.
2. Java Config (전역)
@Bean public Jackson2ObjectMapperBuilderCustomizer customizer() { return builder -> { builder.featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); }; }3. ObjectMapper 직접 설정 (전역)
ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);4. 클래스 단위 (개별 DTO)
@JsonIgnoreProperties(ignoreUnknown = true) // 이 DTO만 알 수 없는 필드 무시 public class OrderSheetRequest { ... } @JsonIgnoreProperties(ignoreUnknown = false) // 이 DTO만 알 수 없는 필드 에러 public class StrictRequest { ... }@JsonIgnoreProperties는 전역 설정보다 우선합니다.
우선순위
@JsonIgnoreProperties (클래스) > application.yml (전역) > Spring Boot 기본값 (false)
주의사항
무시된다는 건 에러가 안 난다는 거지, 데이터가 처리된다는 게 아닙니다. DTO에 필드가 없으면 서버에서 그 값을 읽을 수 없습니다. 실제로 데이터를 사용하려면 DTO에 필드를 추가해야 합니다.
'자바 및 spring boot' 카테고리의 다른 글
Async 와 CompletableFuture 차이 (0) 2026.01.15 Blocking Queue (5) 2025.02.25 [Kafka] 멱등성/At least once/At most once/Exactly once (0) 2025.02.25 LocalDateTime 직렬화 역직렬화 오류 (0) 2025.02.10 [JPA] @Modifying이란? (0) 2025.02.07