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. 网站跳转到cgi-sys/defaultwebpage.cgi的原因和解决方式

    cpanel遇到这种问题,看了这篇文章老鹰主机域名解析A记录教程–关于cgi-sys/defaultwebpage.cgi后,尝试后     首先ping 域名,结果如下     看到没有ping结果 ...

  2. 使用SoapUI生成WS请求报文

    WSDL地址示例:http://10.1.84.10:8100/webService/common/mail?wsdl   打开SoapUI,创建一个Project,输入wsdl地址就ok. 1.访问 ...

  3. HTML5 API—无刷新更新地址 history.pushState/replaceState方法(例子) (转)

    尽管是上面讲到的<JavaScript高级程序设计>(第二版)中提到,BOM中的location.path/query…… (window.location)在通过JavaScript更改 ...

  4. BZOJ 2466 中山市选2009 树 高斯消元+暴力

    题目大意:树上拉灯游戏 高斯消元解异或方程组,对于全部的自由元暴力2^n枚举状态,代入计算 这做法真是一点也不优雅... #include <cstdio> #include <cs ...

  5. mysql-5.7中innodb_buffer_pool页面淘汰算法

    一. 什么是innodb_buffer_pool: innodb_buffer_pool是一块内存区域,innodb用它来缓存数据,索引,undo,change buffer ... : 这块区域又被 ...

  6. 使用国内镜像composer安装laravel

    1.安装 Laravel,创建blog项目 首先先说一下直接安装的方法,要想使用这个方法,首先要FQ(这是我们的基本国情决定的).这样的安装方式有两种: ①.全局安装 使用命令Laravel Inst ...

  7. Oracle学习笔记之五,Oracle 11g的PL/SQL入门

    1. PL/SQL概述 PL/SQL(Procedural Language/SQL)是Oracle的专用语言,是对标准SQL语言的扩展,它允许在其内部嵌套普通的SQL语句,还可以定义变量和常量,允许 ...

  8. 使用.net的跟踪诊断来记录wcf消息

    首先在项目的config文件中定义以下结点: <system.diagnostics> <sources> <source name="System.Servi ...

  9. js的一些代码…

    获取请求的参数 例:VisitPhoto.aspx?imgurl=http://s.cn.bing.net/az/hprichbg/rb/BottlenoseDolphinSurface_ZH-CN1 ...

  10. 【Android】16.5 Android内置的系统服务

    分类:C#.Android.VS2015: 创建日期:2016-03-01 一.简介 实际上,在Android.Content.Context类中,Android已经提供了多种类型的系统服务,这些服务 ...