java javax.ws.rs.NotSupportedException:找不到类型的消息正文阅读器:类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29366840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:07:10  来源:igfitidea点击:

javax.ws.rs.NotSupportedException: Could not find message body reader for type: class

javajsonweb-servicesmavenjersey

提问by SHILPA AR

I tried adding the below dependency in pom.xml

我尝试在 pom.xml 中添加以下依赖项

<!-- Jersey-Json -->
    <dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.8</version>
    </dependency>

and also the below web.xml

还有下面的 web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app>
<servlet>
 <servlet-name>jersey-serlvet</servlet-name>
 <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
 <!-- <init-param>
  <param-name>com.sun.jersey.config.property.packages</param-name>
  <param-value>com.mkyong.rest</param-value>
 </init-param> -->
 <init-param>
  <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
  <param-value>true</param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
  </servlet>
 
  <servlet-mapping>
 <servlet-name>jersey-serlvet</servlet-name>
 <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>

as per other posts. But I am still getting the

按照其他帖子。但我仍然得到

2015-03-31T15:52:08.771+0530 WARN : loggerName="o.j.resteasy.core.ExceptionHandler" threadName="qtp1558867745-18" txnId="" failed to execute javax.ws.rs.NotSupportedException: Could not find message body reader for type: class com.apple.ist.curo.es.data.cdto.RequestCDTO of content type: text/plain;charset=UTF-8 at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.throwReaderNotFound(ServerReaderInterceptorContext.java:52) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:150) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:89) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:112) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:288) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:242) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:229) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.7.Final.jar:na] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.7.Final.jar:na] at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [javax.servlet-api-3.1.0.jar:3.1.0] at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800) [jetty-servlet-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587) [jetty-servlet-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577) [jetty-security-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-servlet-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.Server.handle(Server.java:497) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) [jetty-io-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620) [jetty-util-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540) [jetty-util-9.2.5.v20141112.jar:9.2.5.v20141112] at java.lang.Thread.run(Thread.java:744) [na:1.7.0_51]

2015-03-31T15:52:08.771+0530 警告:loggerName="ojresteasy.core.ExceptionHandler" threadName="qtp1558867745-18" txnId="" 无法执行 javax.ws.rs.NotSupportedException:找不到消息正文阅读器类型:类 com.apple.ist.curo.es.data.cdto.RequestCDTO 内容类型:text/plain;charset=UTF-8 at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.throwReaderNotFound(ServerReaderInterceptorContext.java :52) ~[resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73) ~[resteasy-jaxrs-3.0.7. Final.jar:na] 在 org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50) ~[resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59) ~[resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.core。 interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53) ~[resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:150) ~[resteasy -jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:89) ~[resteasy-jaxrs-3.0.7.Final.jar:na] 在 org .jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:112) ~[resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:288) ~[resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:242) ~[resteasy-jaxrs-3.0.7.Final.jar :na] 在 org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:229) ~[resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.core.SynchronousDispatcher.invoke (SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.7. Final.jar:na] 在 org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy .plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.7.Final.jar:na] 在 org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.7.Final.jar:na] 在 javax.servlet.http .HttpServlet.service(HttpServlet.java:790) [javax.servlet-api-3.1.0.jar:3.1.0] 在 org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800) [jetty- servlet-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587) [jetty-servlet-9.2.5.v20141112.jar:9.2. 5.v20141112] 在 org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty .security.SecurityHandler.handle(SecurityHandler.java:577) [jetty-security-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.server.session。SessionHandler.doHandle(SessionHandler.java:223) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-servlet-9.2.5.v20141112.jar :9.2.5.v20141112] 在 org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org. eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.server.handler.ScopedHandler。 handle(ScopedHandler.java:141) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.server.handler.HandlerWrapper。handle(HandlerWrapper.java:97) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] at org.eclipse.jetty.server.Server.handle(Server.java:497) [jetty-server -9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) [jetty-server-9.2.5.v20141112.jar:9.2.5 .v20141112] 在 org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.io。 AbstractConnection$2.run(AbstractConnection.java:540) [jetty-io-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620) ) [jetty-util-9.2.5.v20141112.jar:9.2.5.v20141112] 在 org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540) [jetty-util-9.2.5 .v20141112.jar:9.2.5。v20141112] 在 java.lang.Thread.run(Thread.java:744) [na:1.7.0_51]

My code is as below:

我的代码如下:

@POST
@Path(PERSON_SALARY_PATH)
@Produces(MediaType.APPLICATION_JSON)
public String getSalary(@RequestBody RequestCDTO requestCDTO) {

回答by Will

In my code, it works after adding dependency below

在我的代码中,它在下面添加依赖项后工作

<dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-Hymanson2-provider</artifactId>
        <version>3.0.19.Final</version>
    </dependency>

回答by SHILPA AR

Add @Consumes(MediaType.APPLICATION_JSON) and make sure you set the request header "Content-Type:application/json". The former I don't think is required, but you should leave it anyway. The latter is the most important. For some reason your request is getting sent out with a "text/plain" header

添加@Consumes(MediaType.APPLICATION_JSON) 并确保设置请求标头“Content-Type:application/json”。前者我认为不是必需的,但无论如何你应该离开它。后者是最重要的。出于某种原因,您的请求以“文本/纯文本”标头发送

The above comment by peeskillet is the right answer.

peeskillet的上述评论是正确的答案。