jackson用法
ObjectMapper mapper=new ObjectMapper(); //3.调用mapper的writeValueAsString()方法把一个对象或集合转为json字符串 Customer customer=new Customer("aaa", "333"); String jsonStr=mapper.writeValueAsString(customer); System.out.println(jsonStr); //4.注意:jackson使用getter方法来定位json对象的属性 //5.可以通过添加注解JsonIgnore忽略某一个getter定义的属性 List<Customer> customers=Arrays.asList(customer,new Customer("bb", "213")); jsonStr=mapper.writeValueAsString(customers); System.out.println(jsonStr);