net.sf.json.JSONException: Object is null

前端之家收集整理的这篇文章主要介绍了net.sf.json.JSONException: Object is null前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Spring+CXF的webService服务端调用时报如下错误

[ WARN]_2018-05-17 11:16:18 - org.apache.cxf.common.logging.LogUtils.doLog(LogUtils.java:449):Application {http://aiocs.openboss.asiainfo.com/services/CRMProcessSheet}CRMProcessSheetService#{http://aiocs.openboss.asiainfo.com/services/CRMProcessSheet}replyWorkSheet has thrown exception,unwinding now
org.apache.cxf.interceptor.Fault: Object is null
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162)
at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:267)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128)
at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.invoke(AbstractJAXWSMethodInvoker.java:232)
at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:85)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:74)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$2.run(ServiceInvokerInterceptor.java:126)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:131)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:252)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:299)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:218)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:274)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:677)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: net.sf.json.JSONException: Object is null
at net.sf.json.JSONNull.isEmpty(JSONNull.java:69)
at Serializer_1.write1(Unknown Source)
at Serializer_1.write(Unknown Source)
at com.alibaba.fastjson.serializer.ListSerializer.write(ListSerializer.java:127)
at com.alibaba.fastjson.serializer.MapSerializer.write(MapSerializer.java:186)
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:374)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:595)
at com.alibaba.fastjson.JSON.toString(JSON.java:589)
at com.cmos.ngroute.ws.eoms.server.CRMProcessSheetImpl.replyWorkSheet(CRMProcessSheetImpl.java:346)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
at org.apache.cxf.jaxws.JAXWSMethodInvoker.performInvocation(JAXWSMethodInvoker.java:66)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
... 47 more

上网查找一些帖子,有不同说法,有的说net.sf.json.JSONArray包不太好用,还有说未初始化,查看代码如下:

List attachInfoList = InterUtils.parseAttachRef(attachRef);
		HashMap<String,Object> attachMap = null;
		if(attachInfoList.size()>0){
			attachMap = new HashMap<String,Object>();
			AttachInfo attachInfo = null;
			for (int i = 0; i < attachInfoList.size(); i++) {
				attachInfo = (AttachInfo)attachInfoList.get(i);
				attachMap.put("attachName",attachInfo.getAttachName());
				attachMap.put("attachPath",attachInfo.getAttachURL());
				attachMap.put("attachSize",attachInfo.getAttachLength());
			}
		}

感觉有可能是attachMap未初始话导致的问题,于是编写以下测试类:

import java.util.HashMap;
import java.util.List;
import net.sf.json.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cmos.csf.api.client.extend.CsfInputObject;
import com.cmos.ngroute.ws.utils.AttachInfo;
import com.cmos.ngroute.ws.utils.InterUtils;

public class TestReqJson {
	public static void main(String[] args) {
		String attachRef = "<attachRef><attachInfo><attachName>1.docx</attachName><attachURL>http://00.00.00.00:81/accessories/uploadfile/sheet/complaint/20171226161905.docx</attachURL><attachLength>11670</attachLength></attachInfo></attachRef>";
//		String attachRef = "";
		List attachInfoList = InterUtils.parseAttachRef(attachRef);
		HashMap<String,Object> attachMap = new HashMap<String,Object>();
		if(attachInfoList.size()>0){
			AttachInfo attachInfo = null;
			for (int i = 0; i < attachInfoList.size(); i++) {
				attachInfo = (AttachInfo)attachInfoList.get(i);
				attachMap.put("attachName",attachInfo.getAttachLength());
			}
		}
		JSONArray attachJson = JSONArray.fromObject(attachMap);
		CsfInputObject csfInputObject = new CsfInputObject();
		JSONObject reqJson = new JSONObject();
	    reqJson.put("sheetType","56");
	    reqJson.put("serviceType",0);
	    reqJson.put("serialNo","20180516080840X320657447");
	    reqJson.put("attachRef",attachJson);
	    String s = reqJson.toString();
	    System.out.println(s);
	    csfInputObject.setObject(reqJson.toString());
	}
}




猜你在找的Json相关文章