VO,JAVA -> JSON 변경( null empty 공백 제거)



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
31
32
public class test {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        test1 t = new test1();
 
        String json1 = "";
        String json2 = "";
        try {
            ObjectMapper mapper1 = new ObjectMapper();
            ObjectMapper mapper2 = new ObjectMapper();
            mapper1.setSerializationInclusion(Include.NON_EMPTY);
            json1 = mapper1.writeValueAsString(t);
            json2 = mapper2.writeValueAsString(t);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        System.out.println(json1);
        System.out.println(json2);
        // {"t1":"1","t2":"2"}
        // {"t1":"1","t2":"2","t3":null,"t4":""}
    }
 
}
 
class test1 {
    public String t1 = "1";
    public String t2 = "2";
    public String t3 = null;
    public String t4 = "";
 
}
 
cs


jackson-annotations-2.5.0.jar

jackson-core-2.5.2.jar

jackson-databind-2.5.2.jar


lib 파일


+ Recent posts