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. Mysql 5.7 从节点配置多线程主从复制

    Mysql 采用多线程进行复制是从 Mysql 5.6 开始支持的内容,但是 5.6 版本下有缺陷,虽然支持多线程,但是每个数据库只能一个线程,也就是说如果我们只有一个数据库,则主从复制时也只有一个线 ...

  2. 【转载】CodeLite汉化

    这几天在Ubuntu下做程序想找一个代码提示功能比较好的IDE但又不想用NETBEANS和ECLIPSE,找到CodeLite但是它是全英文的,比较晕.找了一下,下载了一个windows版的准备回去研 ...

  3. Mac 通过活动监视器关闭卡死进程

    前言: 心好累,Lantern太不省事了 之前装过之后,就设定了开启自启动,搞得我上网都受影响(这玩意,qq没事,但是网易云之类的一些软件上网都不行了...就是这玩意搞的鬼) 没办法,点击关闭吧... ...

  4. OOAD和UML

    ooad: object oriented analysis designer 又有两个分支: ooa(object oriented analysis):what to do ood(object  ...

  5. Google的创新九原则(转)

    原文url:http://www.365xiaoxi.com/All/News/2013-11-22/6432.html 想知道是什么让Google成为生产力与创造力的圣杯?当然不是喝山景城脚下的神水 ...

  6. windows下使用mongodb

    ********************************************************************* ERROR: dbpath (\data\db\) does ...

  7. python学习笔记——多进程中的锁Lock

    1 进程锁 python编程中,引入了对象互斥锁的概念,来保证共享数据操作的完整性. 每个对象都对应于一个可称为“互斥锁”的标记,这个标记用来保证在任一时刻,只能有一线程访问对象. 在python中我 ...

  8. C#:小写金额转换为大写

    #region 小写金额转换为大写 public static string CurrToChnNum(double Currnum) { string sResult = ""; ...

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

    2014-06-01 Created By BaoXinjian

  10. 使用matlab处理图像的基础知识

    MATLAB基本函数一 矩阵运算 1.基本算数运算(加减乘除) + -运算要求矩阵维数相同,例m*n * /运算,例A=B*C,B矩阵是m*n矩阵,B是n*p矩阵,则A是m*p矩阵 A/B相当于A*i ...