码迷,mamicode.com
首页 > 编程语言 > 详细

jackson2.8.4java对象序列化成json字符串格式化时间

时间:2017-06-14 20:09:20      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:bsp   nbsp   object   sys   div   blog   int   ring   simple   

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字符串格式化时间

标签:bsp   nbsp   object   sys   div   blog   int   ring   simple   

原文地址:http://www.cnblogs.com/520playboy/p/7010607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!