Bean을 json으로 전달하는 과정에서 properties에 null이 있으면 수신 측에서는 귀찮은 null 체크 작업을 해야 한다. 이를 줄이기 위해서 송신 측에서 예쁘게 null을 빼고 주는 것이 좋다.

 

관련 자료를 찾아보니 아래 내용과 같다. Bean에 해당 값을 넣어주니 더 이상 null인 값은 전달하지 않는다. 발생하지 않는다.

 

http://wiki.fasterxml.com/JacksonAnnotationSerializeNulls

 

ObjectMapper mapper = new ObjectMapper();
mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
// no more null-valued properties

@JsonSerialize(include=JsonSerialize.Inclusion.NON_DEFAULT)
  public class MyBean {
    // ... only serialize properties with values other than what they default to
  }
 
 
Posted by '김용환'
,