如何使用XML中的CXF JAX-RS和Jackson 2配置服务器返回的日期格式? [英] How do I configure the date format the server returns using CXF JAX-RS and Jackson 2 in XML?

查看:164
本文介绍了如何使用XML中的CXF JAX-RS和Jackson 2配置服务器返回的日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多精力才弄明白,所以我将回答下面的问题。此答案不使用注释,也不需要创建其他类。

This took me a lot of effort to figure out so I'm going to answer the question below. This answer doesn't use annotations and does not require creating additional classes.

推荐答案

你把它放在spring xml上下文配置中:

You put this in your spring xml context configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

...

<bean id="jacksonMapper" class="com.fasterxml.jackson.databind.ObjectMapper">
    <property name="dateFormat">
        <bean class="java.text.SimpleDateFormat">
            <constructor-arg type="java.lang.String" value="yyyyMMdd'T'HHmmss.SSSZ"/>
        </bean>
    </property>
</bean>
<bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"
      p:mapper-ref="jacksonMapper"/>

...

     <jaxrs:providers>
        <ref bean="jsonProvider"></ref>
     </jaxrs:providers>
  </jaxrs:server>

这篇关于如何使用XML中的CXF JAX-RS和Jackson 2配置服务器返回的日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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