RESTEasy: Could not find writer for content-type application/json type

前端 未结 4 445
甜味超标
甜味超标 2020-12-03 18:55

I have a restful service (post) that consumes (application/json) and produces (application/json). The single param for this service is an annotated java object.

I am

相关标签:
4条回答
  • 2020-12-03 19:17

    If you plan to use newer versions of resteasy that implement JAX-RS 2.0, the following dependencies should solve your problem:

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>3.0.5.Final</version>
    </dependency>
    
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>jaxrs-api</artifactId>
        <version>3.0.5.Final</version>
    </dependency>
    
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>3.0.5.Final</version>
    </dependency>
    
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson2-provider</artifactId>
        <version>3.0.5.Final</version>
    </dependency>
    
    0 讨论(0)
  • 2020-12-03 19:25

    If you have all necessary dependencies applied in your project, check if your class implements Serializable.

    @XmlRootElement
    public class MyClass implements Serializable {
        //filds
    }
    

    Maybe it solve your problem.

    0 讨论(0)
  • 2020-12-03 19:33

    I am using all libraries included (maven project), but still when running as standalone application, generated by maven-assembly-plugin, I got same error, but when running from IDE it works without problem.

    I also had problem with log4j2 logging as it was completely broken when running as standalone fat jar application (in IDE works perfectly), so I first focus on solving this:

    Log4j2 configuration not found when running standalone application builded by shade plugin

    So I solved problem with missing provider and log4j2 by migrating from maven-assembly-plugin to maven-shade-plugin

    0 讨论(0)
  • 2020-12-03 19:38
    <dependency>
          <groupId>org.codehaus.jackson</groupId>
          <artifactId>jackson-mapper-asl</artifactId>
          <version>${jackson-mapper-asl.version}</version>
          <scope>runtime</scope>
       </dependency>
    
       <dependency>
          <groupId>javax.xml.bind</groupId>
          <artifactId>jaxb-api</artifactId>
          <version>${jaxb-api.version}</version>
          <scope>runtime</scope>
       </dependency>
    

    This is just more than enough.

    Refer here: http://howtodoinjava.com/2012/12/15/how-to-write-restful-webservices-using-spring-3-mvc/

    0 讨论(0)
提交回复
热议问题