- 객체의 필드가 명시된 JsonInclude의 조건을 만족할 때만 역직렬화를 하도록 한다.
- 적용 예시
public class Test{
public static void main(String[] args) throws JsonProcessingException {
People people = new People();
people.setName(null);
people.setEmail("email");
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(people);
System.out.println(json);
}
}
@Setter
@NoArgsConstructor
@JsonInclude(Include.NON_EMPTY) // null이 아닌 것만 직렬화/역직렬화가 가능하도록 조건을 검
class People{
private String name;
private String email;
}
- 출력 예시 : null이 아닌 email 만 출력된 것을 볼 수 있다.
{"email":"email"}