JAX-RS Jackson Json提供者日期格式问题 [英] JAX-RS Jackson Json Provider Date Format Issue

查看:190
本文介绍了JAX-RS Jackson Json提供者日期格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写下以下问题:

Jersey + Jackson JSON日期格式序列化 - 如何更改格式或使用自定义JacksonJsonProvider

我想知道


  • 杰克逊是否指定将json日期格式规范化为unix时间整数?

后续问题...


  • 有吗最近一直在改变立场吗?

  • 日期格式不应该标准化为jaxb xml输出提供的相同格式吗?

  • 为什么/为什么不呢?

  • 为解决这个问题付出的努力是什么?

  • 让RestEasy提供了一个json提供者缓解措施,可以输出一个普遍可识别的json日期日期格式?

  • Has there been a change in its stance anytime recently?
  • Shouldn't a date format be normalised to the same format provided by jaxb xml output?
  • why/why not?
  • any effort put into resolving this issue?
  • has RestEasy provided a json provider mitigation that would output json date in a generally recognisable date format?

推荐答案

对不起有人大喊大叫大声 - 我在这里找到答案

Sorry people for yelling out loud - I found the answers here

http:// wiki .fasterxml.com / JacksonFAQDateHandling

这里

http://wiki.fasterxml.com/JacksonFAQ#Serializing_Dates

这里

http://wiki.fasterxml.com/JacksonHowToCustomSerializers

此处

http://jackson.codehaus.org/1.1.2/javadoc/org/codehaus/jackson/map/ util / StdDateFormat.html

使用@JsonSerialize(使用= ...)方式:

Using the @JsonSerialize(using= ... ) way:

public class JsonStdDateSerializer
extends JsonSerializer<Date> {
  private static final DateFormat iso8601Format =
    StdDateFormat.getBlueprintISO8601Format();

  @Override
  public void serialize(
    Date date, JsonGenerator jgen, SerializerProvider provider)
  throws IOException, JsonProcessingException {

    // clone because DateFormat is not thread-safe
    DateFormat myformat = (DateFormat) iso8601Format.clone();
    String formattedDate = myformat.format(date);
    jgen.writeString(formattedDate);
  }
}

这篇关于JAX-RS Jackson Json提供者日期格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆