xml配置如下
<action name="deletePositionAction" class="com.graduation.action.PositionAction" method="deletePosition">
<interceptor-ref name="json"/>
<result type="json">
<param name="root">dataMap</param>
</result>
</action>
传递的JSON的List长度为1时就会报错
org.apache.struts2.json.JSONException: Incompatible types for property setPositions
org.apache.struts2.json.JSONPopulator.convertToCollection(JSONPopulator.java:259)
org.apache.struts2.json.JSONPopulator.convert(JSONPopulator.java:131)
org.apache.struts2.json.JSONPopulator.populateObject(JSONPopulator.java:109)
org.apache.struts2.json.JSONInterceptor.intercept(JSONInterceptor.java:114)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:544)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
java.lang.Thread.run(Thread.java:619)
当传递的List的长度大于1时才能够成功,
进入JSONPopulator调试时发现到convertToCollection函数时,有多个元素是value有方括号包围,只有1个元素时只有花括号~~~求指教!!!
json struts
------解决方案--------------------
------解决方案--------------------
Incompatible types for property setPositions这就告诉你是json的问题了。