티스토리 뷰

 

ObjectMapper의 readValue 이용 시 모르는 value 무시하는 방법

@JsonIgnoreProperties(ignoreUnknown = true)
public class NAME implements Serializable {

    private long value1;
    private long value2;
    private long value3;

VO 쪽에 @JsonIgnoreProperties(ignoreUnknown = true) 를 써준다.

 

 

대소문자 구분 안하게 하기

 

ObjectMapper는 대소문자를 구분해서 아래의 에러가 났다. 

 

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:Unrecognized field "변수명"  not marked as ignorable 

 

이래놓고 변수명 상태가 로그로 나오는데...

 

new ObjectMapper().configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);

아래와 같이 사용하면 된다.

MapperFeature는 com.fasterxml.jackson.databind.MapperFeature; 를 사용한다. 임의로 만든게 아니다.

 

사용예

 

new ObjectMapper().configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIEStrue).readValue(value, VO.class)

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함