java.lang.NoSuchMethodError:com.fasterxml.jackson.databind.SerializationConfig.withDefaultPrettyPrinter

时间:2016-06-20 06:49:58

标签: java jsp fasterxml jackson-dataformat-xml

我想解析一个xml文件并转换为Pojo对象,然后在jsp页面上显示xml文件的内容。 我只使用一个依赖项,

版本:

数据格式依赖关系:

<dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-xml</artifactId>
        <version>2.8.0.rc1</version>
</dependency>

主要逻辑:(JacksonDeserializer.java)

XmlMapper xmlMapper = new XmlMapper();
SimpleModule module = new SimpleModule();
Channel ch = new Channel();
module.addDeserializer(List.class, ch.new ChannelDeserializer());
xmlMapper.registerModule(module);
xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Rss rss = xmlMapper.readValue(new File("filepath"), Rss.class);
Channel channel = rss.getChannel();
JacksonDeserializer obj = new JacksonDeserializer();
List<Item> item = channel.getItem();
obj.setItem(item);

//getter setter method for List<Item> item

index.jsp:

<body>
    <%
    JacksonDeserializer obj = new JacksonDeserializer();
    obj.readXML();
    List<Item> item = obj.getItem();//calling getter method of JacksonDeserializer
    for (Item i : item) {
        %>
        <%="title : " + i.getTitle()%>
        <%="link : " + i.getLink()%>
        <%="description : " + i.getDescription()%>
        <%="pubdate : " + i.getDate()%>
        <%
        }
    %>
</body>

当我运行此WebApplication时, index.jsp 页面显示如下异常:

HTTP状态500 - 内部服务器错误

类型:异常报告

message : Internal Server Error

description : The server encountered an internal error that prevented it from fulfilling this request.

exception : java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.SerializationConfig.withDefaultPrettyPrinter(Lcom/fasterxml/jackson/core/PrettyPrinter;)Lcom/fasterxml/jackson/databind/SerializationConfig;

note :  The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.

服务器日志:

  Info:   visiting unvisited references
  Info:   Loading application [RSSDemo] at [/RSSDemo]
  Info:   RSSDemo was successfully deployed in 212 milliseconds.
  Warning:   StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
  java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.SerializationConfig.withDefaultPrettyPrinter(Lcom/fasterxml/jackson/core/PrettyPrinter;)Lcom/fasterxml/jackson/databind/SerializationConfig;
  at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:86)
  at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:67)
  at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:49)
  at com.mycompany.rssdemo.JacksonDeserializer.readXML(JacksonDeserializer.java:32)
  at org.apache.jsp.index_jsp._jspService(index_jsp.java:63)
  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
  at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
  at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
  at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
  at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
  at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
  at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
  at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
  at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
  at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
  at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
  at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
  at java.lang.Thread.run(Thread.java:745)

当我试图在控制台上显示此内容时,它正以良好的方式显示,但当我尝试在网络上显示此异常时,我只是想知道这是什么问题例外,这是什么解决方案?

0 个答案:

没有答案