일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- JAXBContext
- NoSQL
- spring
- 기출문제
- vue Carousel
- JSON
- 구멍가게코딩단
- bulkinsert
- 마스킹
- query
- Ajax
- 부스트코스
- insertAll
- MariaDB
- INSERT
- swipe 배너
- vscode tutorial
- checkbox
- JQuery
- jdbc
- mysql
- vue.js
- egov
- Tomcat
- 오라클
- mybatis
- jsp
- github
- java
- 정보처리산업기사
Archives
- Today
- Total
개발새발
class 객체에 null값인 객체 미노출 (@JsonInclude) 본문
728x90
반응형
rMate 차트를 사용하면서 데이터를 불러올 때 객체에 null이거나 0인 필드명들이 노출이 되지 않아야
차트에서 데이터를 정확하게 나타낼 수 있다.
따라서, 불필요한 필드들의 null 값 리턴이나 의도적으로 미노출하고자 하는 class에
@JsonInclude 어노테이션을 사용한다.
[@JsonInclude 미사용시 : 기본값]
public static class test {
private int num;
private String name;
private String adress;
private int phoneNum;
}
{
"num" : 1,
"name" : "지나",
"adress" : null,
"phoneNum" : 0
}
[옵션 종류]
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
- primitive 타입이 디폴트 값이면 제외한다. (int / Integer : 0 , boolean / Boolean : false 등)
- Date의 timestamp가 0L이면 제외한다.
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public static class test {
private int num;
private String name;
private String adress;
private int phoneNum;
}
{
"num" : 1,
"name" : "지나",
"adress" : null,
"phoneNum" : 0
}
@JsonInclude(JsonInclude.Include.NON_NULL)
- null은 제외한다.
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class test {
private int num;
private String name;
private String adress;
private int phoneNum;
}
{
"num" : 1,
"name" : "지나",
"phoneNum" : 0
}
이 외에도 다른 옵션들이 있다.
728x90
반응형
'Framework > springboot' 카테고리의 다른 글
[Spring Boot에 lombok추가] (0) | 2019.12.12 |
---|
Comments