参考:http://stackoverflow.com/questions/2519432/jaxb-unmarshal-timestamp
关键词:cxf rest format date
cxf rest默认使用2010-08-23T20:32:43.609+08:00这种时间格式,我们可以通过定义annotation来改变它。
新建annotation:
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class DateAdapter extends XmlAdapter<String, Date> {
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public String marshal(Date v) throws Exception {
return dateFormat.format(v);
}
@Override
public Date unmarshal(String v) throws Exception {
return dateFormat.parse(v);
}
}
使用:
@XmlRootElement(name = "resp")
@XmlAccessorType( XmlAccessType.FIELD )
public class BaseRespObj {
@XmlJavaTypeAdapter(DateAdapter.class)
private Date date;
@XmlElement(name = "infocode")
private ResultCode code;
将注解@XmlJavaTypeAdapter(DateAdapter.class)放在时间属性上即可。此时时间将返回2010-08-23 20:32:43格式。
分享到:
相关推荐
这是一个基于maven构建的java项目,整合了Apache CXF框架,实现restful风格的service
CXF发布的REST服务返回JSON格式数据,只有服务端代码,没有客户端代码,可以通过http://localhost:9999/roomservice/room、http://localhost:9999/roomservice/room/001来访问测试数据。
cxf开发rest风格接口最少jar
本例子是通过CXF服务端来发布Rest服务,同时在客户端进行接收。本例子是自己学习CXF Rest时候写的,希望能给需求的人帮助.CXF的版本号为2.3.3,请自己下载CXF2.3.3的jar包.
cxf rest webervice 实现文件下载
Set up your build for CXF Writing a simple JAX-WS service Set up the HTTP transport
cxf rest最简实例可直接运行,先运行服务,在浏览器中输入项目路径http://localhost:8080/webrest/api/str/abc进行测试
Apache CXF配置REST服务,集成到Spring当中。
apache cxf下开发 REST webservice的说明文档
发布CXF+Spring整合的REST的服务接口完整实例,其中包括数据库连接池,json数据格式传递数据,HttpURLConne的get和post方式调用接口,以及获取访问者ip地址工具类等众多的技术实例。
CXF整合spring实现REST接口开发
CXF spring 提供rest服务输出xml或json等格式数据
Spring CXF Restful 实例
SPRING-MVC-MQ-CXF-REST_Demo
Spring+CXF+Maven+REST方式搭建WebService服务端demo测试用例
使用CXF暴露您的REST服务 简单的例子,完整的配置过程
webservice cxf spring整合返回list,bean,string,json,xml项目完整实例
这个是cxf+spring发布webservice和restservice的服务端项目
CXF2.5.5 api 希望对大家啊有帮助
NULL 博文链接:https://fly2wind.iteye.com/blog/730350