IT/JAVA
VO,JAVA -> JSON 변경( null empty 공백 제거) jar파일
KNOW_KP
2017. 5. 4. 17:27
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 |
lib 파일