JAX-RS 如何传输 JSON 格式的数据 ?

来源:互联网 发布:南京弘历软件 编辑:程序博客网 时间:2024/05/22 10:43

客户端中查询某个用户,获取json时报错
错误内容:Caused by: javax.ws.rs.ProcessingException: No message body writer has been found for class cn.itcast.cxf.domain.User, ContentType: application/json

解决方法: 在pom.xml中引入两个坐标

   <!-- 在CXF扩展提供者,提供转换json接口  -->    <dependency>      <groupId>org.apache.cxf</groupId>      <artifactId>cxf-rt-rs-extension-providers</artifactId>      <version>3.0.1</version>    </dependency>    <!-- cxf 扩展提供者 转换json 默认需求一个工具包  -->    <dependency>      <groupId>org.codehaus.jettison</groupId>      <artifactId>jettison</artifactId>      <version>1.3.7</version>    </dependency>