我使用CXF服務器休息web服務提供傑克遜的供應商,如SimpleDateFormat的日期格式 這裏描述傳遞錯誤的日期格式CXF
How do I configure the date format the server returns using CXF JAX-RS and Jackson 2 in XML?
它可以提供一個日期time.format處理錯誤如爲其定義的,它會產生服務器錯誤。
目標是轉換接收日期,並將其轉換或返回描述錯誤給客戶端
下面的XML配置
<bean id="dataFormat" class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value=" yyyy-MM-dd'T'HH:mm:ssXXX" />
</bean>
<bean id="jaxbAnnIntrospector" class="org.codehaus.jackson.xc.JaxbAnnotationIntrospector" />
<bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper">
<property name="serializationConfig.annotationIntrospector"
ref="jaxbAnnIntrospector" />
<property name="deserializationConfig.annotationIntrospector"
ref="jaxbAnnIntrospector" />
<property name="dateFormat" ref="dataFormat" />
</bean>
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider">
<property name="mapper" ref="objectMapper" />
</bean>
<jaxrs:providers>
...
<ref bean="jsonProvider" />
...
</jaxrs:providers>
服務器錯誤:
java.lang.NoSuchMethodError: javax.ws.rs.ServerErrorException.validate(Ljavax/ws/rs/core/Response;Ljavax/ws/rs/core/Response$Status$Family;)Ljavax/ws/rs/core/Response;
at javax.ws.rs.ServerErrorException.<init>(ServerErrorException.java:101)
at javax.ws.rs.InternalServerErrorException.<init>(InternalServerErrorException.java:80)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:242)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:98)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:218)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:163)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:163)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219)
在此先感謝
請,張貼「規定的日期time.format的代碼,而它爲它定義產生一個服務器錯誤「 –
更新後@IvanPronin – antonio