Java - JSON对象和ListOrderedMap问题
我正在尝试在代码中使用 JSON-lib api 将 java 对象转换为 JSONObject。
我已将以下链接中指定的版本的所有依赖项添加到我的 j2ee Web 模块依赖项
http://json -lib.sourceforge.net/
但是,每当我调用 JSONObject.fromObject() 方法时,我都会收到 NoSuchMethodError。
我还应该指出,完全相同的代码和依赖项可以在我的 tomcat 服务器上运行,但不能在我的 websphere 应用程序服务器上运行。有人知道我可能做错了什么吗?
下面的部分堆栈跟踪:
E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[SpringMVCServlet]: java.lang.NoSuchMethodError: org/apache/commons/collections/map/ListOrderedMap.<init>()V
at net.sf.json.JSONObject.<init>(JSONObject.java:1450)
at net.sf.json.util.CycleDetectionStrategy.<clinit>(CycleDetectionStrategy.java:37)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at net.sf.json.JsonConfig.<clinit>(JsonConfig.java:65)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at net.sf.json.JSONObject.fromObject(JSONObject.java:134)
I am trying to use the JSON-lib api in my code to convert a java object into a JSONObject.
I have added all of the dependencies with the versions specified on the link below to my j2ee web module dependencies
http://json-lib.sourceforge.net/
However, whenever I call the JSONObject.fromObject() method I get NoSuchMethodError.
I should also point out that the exact same code and dependencies work on my tomcat server but do not work on my websphere application server. Does anybody know what I may be doing wrong ?
Partial stack trace below:
E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[SpringMVCServlet]: java.lang.NoSuchMethodError: org/apache/commons/collections/map/ListOrderedMap.<init>()V
at net.sf.json.JSONObject.<init>(JSONObject.java:1450)
at net.sf.json.util.CycleDetectionStrategy.<clinit>(CycleDetectionStrategy.java:37)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at net.sf.json.JsonConfig.<clinit>(JsonConfig.java:65)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at net.sf.json.JSONObject.fromObject(JSONObject.java:134)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的
WEB-INF/lib
中有正确版本的 commons collections jar,然后在您的 WebSphere 管理中设置“首先使用应用程序类加载器加载的类”
选项控制台如图此处Make sure you have the correct version of commons collections jar in your
WEB-INF/lib
and then set the"Classes loaded with application class loader first"
option in your WebSphere admin console as shown here