jackon的jar包下载地址:
http://repo1.maven.org/maven2/com/fasterxml/jackson/
需要下载core里面的3个jar包
测试案例
package com.gyarmy.javabeen; import java.util.Date; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class Customer { public Customer(String name, String id) { super(); this.name = name; this.id = id; } private String name; private String id; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getCity(){ return "Beijing"; } @JsonIgnore public String getBirth(){ return "1990-12-21"; } public static void main(String[] args) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); //mapper Customer customer = new Customer("AtGuigu", "1001"); String jsonStr = mapper.writeValueAsString(customer); System.out.println(jsonStr); } }
0则评论给“java的jackon测试案例”