jackson简单的转化对象
ckage study.lesson.frist;
import org.codehaus.jackson.map.ObjectMapper;
import java.io.IOException;
/**
* Created by cxlings on 2016/1/7.
*/
public class Tester {
public static void main(String[] args) {
String json = "{\"name\":\"小民\",\"age\":\"20\",\"birthday\":844099200000,\"email\":\"xiaomin@sina.com\",\"id\":\"243144312411113242\"}";
/**
* ObjectMapper支持从byte[]、File、InputStream、字符串等数据的JSON反序列化。
*/
ObjectMapper mapper = new ObjectMapper();
User user = null;
try {
user = mapper.readValue(json, User.class);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("age"+user.getAge()+"id="+user.getId());
}
}
package study.lesson.frist;
import java.math.BigInteger;
import java.util.Date;
/**
* Created by cxlings on 2016/3/24.
*/
public class User
{
private String name;
private Integer age;
private Date birthday;
private String email;
private BigInteger id;
public BigInteger getId() {
return id;
}
public void setId(BigInteger id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
把学习一种技术一直坚持下去。