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;
} }

结果{"id":1,"name":"JACK","money":0.0,"birthday":"2013-04-01"}

objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,FALSE); 
禁止使用时间戳(数字),而使用[ISO-8601标准的符号,它得到类似的输出:“1970-01-01T00:00:00.000 +0000”。

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8") 
也可以再类的属性上自定义哪些属性需要自定义序列化 
timezone="GMT+8" 这里是中国的时区 东8区

自定义格式化类 
JsonSerializer<T> 
@JsonSerialize(user=xxx.class)

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);

Notes on java.sql.Date (官方不建议使用此类型)

(aka "Please do NOT use java.sql.Date, ever!")

Although Jackson supports java.sql.Date, there are known issues with respect to timezone handling, partly due to design of this class. It is recommended that this type is avoided, if possible, and regular java.util.Date (orjava.util.Calendar) used instead. If this is not possible, it may be necessary for applications to convert these dates using java.util.Calendar and explicit timezone definition.

Jackson2.1.4 序列化格式化时间的更多相关文章

  1. 在SpringMVC中使用Jackson并格式化时间

    在spring MVC 3中,要实现REST风格的JSON服务,最简单的方式是使用 @ResponseBody 注解.该注解会自动把返回的对象,序列化为JSON. 来看一个最简单的例子.这个例子先使用 ...

  2. SpringBoot中使用Fastjson/Jackson对JSON序列化格式化输出的若干问题

    来源 :https://my.oschina.net/Adven/blog/3036567 使用springboot-web编写rest接口,接口需要返回json数据,目前国内比较常用的fastjso ...

  3. JavaScriptSerializer 序列化json 时间格式

    利用JavaScriptSerializer 序列化json 时间格式,得到的DateTime值值显示为“/Date(700000+0500)/”形式的JSON字符串,显然要进行转换 1.利用字符串直 ...

  4. WP7、WP8 格式化时间为距当前多少时间

    方法一: 使用 toolkit的 RelativeTimeConverter,使用方式 <phone:PhoneApplicationPage.Resources> <toolkit ...

  5. golang 格式化时间为字符串

    package main import ( "fmt" "reflect" "time" ) func main() { //格式化字符串为 ...

  6. php友好格式化时间

    php格式化时间显示 function toTime($time) {//$time必须为时间戳 $rtime = date("Y-m-d H:i",$time); $htime ...

  7. java 格式化时间

    java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); form ...

  8. 封装insertAfter、addClass、格式化时间

    insertAfter,在JS节点操作中,并没有insertAfter方法,因此需要重新封装 function insertAfter(newEle,targetNode) { var oParent ...

  9. Jquery 格式化时间

    我们常常会通过datetime得到时间,但是网页前台往往会显示不同的时间 如:2013-12-15 2013年12月23日 2013 12 15 等多种显示效果,这就需要我们把时间格式化一下. 下面是 ...

随机推荐

  1. 我的硬盘安装ArchLinux+xorg+gnome+美化

    整个安装需要联接网络!现在的xorg为6.8.1,gnome为2.8.0                看了大家为了使用gnome,出现了那么多问题!这里我就推荐一个发行版,再安装上gnome2.8. ...

  2. HDUOJ Children’s Queue

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. sigmoid 函数与 softmax 函数

    sigmoid 函数与 softmax 函数     1. sigmoid 函数       sigmoid 函数又称:logistic函数,逻辑斯谛函数.其几何形状即为一条sigmoid曲线. lo ...

  4. 浅谈 .NET 中的对象引用、非托管指针和托管指针

    目录 前言 一.对象引用 二.值传递和引用传递 三.初识托管指针和非托管指针 四.非托管指针 1.非托管指针不能指向对象引用 2.类成员指针 五.托管指针 前言 本文主要是以 C# 为例介绍 .NET ...

  5. C#实现foreach

    方法:一.继承既有的接口 如:CollectionBase.DictionaryBase class TestForeach: CollectionBase { public void Add(str ...

  6. Form_如何通过标准功能查找数据源(概念)

    2014-06-01 Created By BaoXinjian

  7. IDLE经常使用快捷键汇总

    IDLE(An Integrated DeveLopment Environment for Python)是Python自带的编译器,在刚開始学习的人,或写小程序,或用于验证的时候,经经常使用到!假 ...

  8. TCP数据流

    1. 引言 如果按照分组数量计算,约有一半的TCP报文段包含成块数据(如FTP.电子邮件等),另一半则包含交互数据(如telnet和rlogin).如果按照字节计算,则成块数据与交互数据的比例约为90 ...

  9. android购物车遇到的问题

    近期 做购物车的时候 ,遇到几个问题.如今 总结例如以下: 1:不让listview复用组件(购物车.或者有特殊操作的时候): 自己保存全部的view对象 public View getView(fi ...

  10. PIVOT运算符使用(动态行转列)

    PIVOT运算符用于在列和行之间对数据进行旋转或透视转换,同时执行聚合运算 官方的语法如下: PIVOT( 聚合函数(value_column) FOR pivot_column IN(<col ...