No message body writer has been found for class com.alibaba.fastjson.JSONObject, ContentType: */*
1:当使用 cxf 发布服务时,要求返回值类型为xml,或者json等
@Path("/searchProductByText")
@GET
@Produces({"application/xml", "application/json"})
JSONObject productSearch(@QueryParam("text") String text);
但是 cxf不支持解析 JSONObject 等对象
进行访问时将会返回 No message body writer has been found for class com.alibaba.fastjson.JSONObject, ContentType: */*
2:解决方法,定义一个pojo,里面包含 JSONObject 引用。将返回的JSONObject包含在 自定义的 POJO中,使用注解将pojo定义为能被解析为xml形式等。
package com.search.pojo; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude; import javax.xml.bind.annotation.XmlRootElement; //@JsonInclude(JsonInclude.Include.NON_NULL)//不包含有null值的字段,即字段值为null的转换为json字符串时会被省略
@XmlRootElement(name="MyJSONObject")
public class MyJSONObject {
JSONObject jsonObject; public JSONObject getJsonObject() {
return jsonObject;
} public void setJsonObject(JSONObject jsonObject) {
this.jsonObject = jsonObject;
}
}
3:在实现类中,返回对象变为 pojo
MyJSONObject myJSONObject=new MyJSONObject();
myJSONObject.setJsonObject(jsonObject);
return myJSONObject;
4:接口 方法 返回 也变为 pojo
@Path("/searchProductByText")
@GET
@Produces({"application/xml", "application/json"})
MyJSONObject productSearch(@QueryParam("text") String text);
5 可以返回值了。
6:前端接到响应体中的xml,可以转化为json
httpResponse = httpUtil.HttpGet(requestParamMap, url);
HttpEntity entity = httpResponse.getEntity();
String s = EntityUtils.toString(entity);
//将返回的xml字符串形式转化为json格式
org.json.JSONObject xmlJSONObj = XML.toJSONObject(s);
jsonObject = (JSONObject) JSON.parse(xmlJSONObj.toString());
No message body writer has been found for class com.alibaba.fastjson.JSONObject, ContentType: */*的更多相关文章
- webservice接口问题:Payload: No message body writer has been found for class domain, ContentType: application/xml
当在使用cxf-rs的webservice的时候,有时候在传输数据,会发生这种错误 错误代码: Response-Code: 500 Content-Type: text/plain Headers: ...
- cxf maven 依赖 No message body writer foud.. contenttype:application/json
最近使用cxf发布rest服务时遇到了如题的异常,最后发现是缺少依赖的问题.ps:我并没有使用spring cxf基本运行需要如下依赖 1 <dependency> <groupId ...
- SpringBoot之KindEditor文件上传
后端核心代码如下: package com.blog.springboot.controller; import java.io.BufferedOutputStream; import java.i ...
- java 微信开发的工具类WeChatUtils
import com.alibaba.fastjson.JSONObject;import com.bhudy.entity.BhudyPlugin;import com.bhudy.service. ...
- 【学习】014 深入理解Http协议
Http协议入门 什么是http协议 http协议: 对浏览器客户端 和 服务器端 之间数据传输的格式规范 查看http协议的工具 1)使用火狐的firebug插件(右键->firebug-& ...
- Dubbo入门到精通学习笔记(八):ActiveMQ的安装与使用(单节点)、Redis的安装与使用(单节点)、FastDFS分布式文件系统的安装与使用(单节点)
文章目录 ActiveMQ的安装与使用(单节点) 安装(单节点) 使用 目录结构 edu-common-parent edu-demo-mqproducer edu-demo-mqconsumer 测 ...
- hive数据仓库入门到实战及面试
第一章.hive入门 一.hive入门手册 1.什么是数据仓库 1.1数据仓库概念 对历史数据变化的统计,从而支撑企业的决策.比如:某个商品最近一个月的销量,预判下个月应该销售多少,从而补充多少货源. ...
- J2EE项目开发中常用到的公共方法
在项目IDCM中涉及到多种工单,包括有:服务器|网络设备上下架工单.服务器|网络设备重启工单.服务器光纤网线更换工单.网络设备撤线布线工单.服务器|网络设备替换工单.服务器|网络设备RMA工单.通用原 ...
- HttpClient相关
HTTPClient的主页是http://jakarta.apache.org/commons/httpclient/,你可以在这里得到关于HttpClient更加详细的信息 HttpClient入门 ...
随机推荐
- 探求C#.Net中ArrayList与Array的区别
ArrayList与Array的区别概述 ArrayList 是数组的复杂版本.ArrayList 类提供在大多数 Collections 类中提供但不在 Array 类中提供的一些功能.例 ...
- Delphi XE开发 Android 开机自动启动
https://blog.csdn.net/tanqth/article/details/74357209 Android 下的广播 在Android下,要让我们开发的APP能在开机时自动启动,必须使 ...
- mac下用户用户组命令行操作
使用mac的时候需要像linux一样对用户和群组进行操作,但是linux使用的gpasswd和usermod在mac上都不可以使用,mac使用dscl来对group和user操作. 查看用户组: ds ...
- iOS - 处理计算精度要求很高的数据,floatValue,doubleValue等计算不精确问题
.问题描述:服务器返回的double类型9...94的数字时 .之前处理方式是 :(从内存.cpu计算来说double都是比较合适的,一般情况下都用double) goodsPrice.floatVa ...
- Centos6.5安装mysql 5.7
1.在官网下载安装包:https://dev.mysql.com/downloads/mysql/5.7.html#downloads mysql-5.7.10-linux-glibc2.5-x86_ ...
- JAVAORM框架之Mybatis (Ibatis) 详解
目录 Mybatis基础概念 Mybatis开放方式演进 Mybatis框架核心要点 关联查询 延迟加载(懒加载) 动态SQL Mybatis缓存 Mybatis逆向工程 PageHelper分页插件 ...
- windows下gcc的安装
首先打开 www.mingw.org . www.mingw.org 直接点击右上方的 Download Installer 即可下载. 点击 Download Installer 进入下载页 ...
- URAL 1277 - Cops and Thieves - [无向图点带权的最小点割]
题目链接:https://cn.vjudge.net/problem/URAL-1277 The Galaxy Police (Galaxpol) found out that a notorious ...
- HDU - 5651 xiaoxin juju needs help 逆元模板
http://acm.hdu.edu.cn/showproblem.php?pid=5651 题意:生成回文串.输出所有回文串的可能数. 题解:mod除法会损失高位,用逆元来代替除法,模板如下 ac代 ...
- HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...