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. 【LeetCode】56. Merge Intervals

    Merge Intervals Given a collection of intervals, merge all overlapping intervals. For example,Given  ...

  2. 阿里云ECS服务器Linux环境下配置php服务器(一)--基础配置篇

    开始安装软件了,我们需要安装的软件有apache,php和MySQL. ps:如果你购买的是北京的服务器,有个安全组需要设置,我全部用的默认设置,暂时还没发现会有什么影响. 首先关闭SELINUX(S ...

  3. Android Fragment之间传递List数据

    要说的是在两个Fragment之间传递List数据,比如有个List<User>,以及传递字符串数据,比如testId,该如何从FragmentA传递到FragmentB呢? 下面这个例子 ...

  4. web.csproj Compile 下出现两个同名 xxx.cs 项目中出现两个xxx.cs

    删掉一个就好了 ItemGroup Compile 为加载的cs代码文件

  5. python学习笔记011——内置函数filter()

    1 描述 filter() 函数用于过滤序列,过滤掉不符合条件的元素,返回由符合条件元素组成的新列表. 2 语法 filter(function, iterable) function -- 函数,过 ...

  6. 《JAVA与模式》之状态模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述状态(State)模式的: 状态模式,又称状态对象模式(Pattern of Objects for States),状态模式是对象的行为 ...

  7. python AES双向对称加密解密

    高级加密标准(Advanced Encryption Standard,AES),在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.这个标准用来替代原先的DES,已经被多方分 ...

  8. mod_fastcgi和mod_fcgid的区别

    mod_fcgid是一个跟mod_fastcgi二进制兼容的Apache module. 原 来的mod_fastcgi因为实现方式的限制,所以可能会创建了很多不必要的进程,而实际上只需要更少的进程就 ...

  9. 生产环境JAVA进程高CPU占用故障排查

    问题描述:生产环境下的某台tomcat7服务器,在刚发布时的时候一切都很正常,在运行一段时间后就出现CPU占用很高的问题,基本上是负载一天比一天高. 问题分析:1,程序属于CPU密集型,和开发沟通过, ...

  10. Python学习笔记11:标准库之文件管理(os包,shutil包)

    1 os包 os包包含各种各样的函数,以实现操作系统的很多功能.这个包很庞杂.os包的一些命令就是用于文件管理. 我们这里列出最经常使用的: mkdir(path) 创建新文件夹.path为一个字符串 ...