jackson2.8.4java对象序列化成json字符串格式化时间
Posted 坏~牧羊人
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jackson2.8.4java对象序列化成json字符串格式化时间相关的知识,希望对你有一定的参考价值。
public class User {
private int id; private Date birthday; private double money; private String name; public User() { } public User(int id, String name, Date birthday) { super(); this.id = id; this.name = name; this.birthday = birthday; } public User(int id, String name, double money, Date birthday) { super(); this.id = id; this.name = name; this.money = money; this.birthday = birthday;} public Date getBirthday() { return birthday; } public int getId() { return id; } public double getMoney() { return money; } public String getName() { return name; } public void setBirthday(Date birthday) { this.birthday = birthday; } public void setId(int id) { this.id = id; } public void setMoney(double money) { this.money = money; } public void setName(String name) { this.name = name; } }
ObjectMapper mapper = new ObjectMapper(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); mapper.setDateFormat(format); User user = new User(1,"JACK",new Date()); String outJson = mapper.writeValueAsString(user); System.out.println(outJson);
结果{"id":1,"name":"JACK","money":0.0,"birthday":"2013-04-01"}
以上是关于jackson2.8.4java对象序列化成json字符串格式化时间的主要内容,如果未能解决你的问题,请参考以下文章