javax.ws.rs.ProcessingException: could not find writer for content-type application/json

13,357

So, after looking up on JBoss docs I think I've found your issue:

You're using resteasy-client-3.0.4.Final which depends on resteasy-jaxrs-3.0.4.Final, as stated here.

Now the thing is, on resteasy-jaxrs-3.0.4.Final the class CaseInsensitiveMap<V> has a different hierarchy than the one of resteasy-jaxrs-3.0.12.Final.

My suggestion is for you to upgrade your resteasy-client for the version 3.0.12.

EDIT

Your pom.xml should include these dependencies. Validate which ones you don't have and update your Maven project:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.0.12.Final</version>
</dependency>

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>jaxrs-api</artifactId>
    <version>3.0.12.Final</version>
</dependency>

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxb-provider</artifactId>
    <version>3.0.12.Final</version>
</dependency>

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>3.0.12.Final</version>
</dependency>
Share:
13,357
Kaushi
Author by

Kaushi

Updated on July 29, 2022

Comments

  • Kaushi
    Kaushi almost 2 years

    I am new to REST web services. Am trying @post and @consumes annotation as below

    @POST
    @Path("/post")
    @Consumes("application/json")
    public Response createProductInJSON(Product product) {
        String result = "Product created : " + product;
        return Response.status(201).entity(result).build();
    }
    

    Edit Product Class

    public class Product {
        String name;
        int qty;
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getQty() {
            return qty;
        }
    
        public void setQty(int qty) {
            this.qty = qty;
        }
    }
    

    Now I want to test this, so am using the below code to test.

    Product product=new Product();
        product.setName("windows_phone");
        product.setQty(4);
    
        ResteasyClient client = new ResteasyClientBuilder().build();
        ResteasyWebTarget target = client.target("http://localhost:8080/Rest_Services/practice/service/post");
    
        Response response = target.request().post(Entity.entity(product, "application/json"));
    
        if (response.getStatus() != 200) {
            throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus());
        }
    
        System.out.println("Server response : \n");
        System.out.println(response.readEntity(String.class));
        response.close();
    

    Am getting the below error when executed.

    log4j:WARN No appenders could be found for logger (org.jboss.resteasy.plugins.providers.DocumentProvider).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "main" javax.ws.rs.ProcessingException: Unable to invoke request
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:287)
    
    Caused by: javax.ws.rs.ProcessingException: could not find writer for content-type application/json type: com.model.Product
    at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:138)
    

    Below are the Jars am using.

    enter image description here

    EDIT 3 POM.XML

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    <groupId>rest_maven</groupId>
    <artifactId>rest_maven</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.annotation</groupId>
            <artifactId>jboss-annotations-api_1.1_spec</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>net.jcip</groupId>
            <artifactId>jcip-annotations</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>3.0.12.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>3.0.12.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>jaxrs-api</artifactId>
            <version>3.0.12.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxb-provider</artifactId>
            <version>3.0.12.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson2-provider</artifactId>
            <version>3.0.12.Final</version>
        </dependency>
    </dependencies>
    </project>
    

    settings.xml

    <settings>
    <localRepository>Z:\PROD_Deploy\mvn\repository</localRepository>
    
    <proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <username>xxx</username>
      <password>xxx</password>
      <host>xxx</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    

    Please help me get through this error. Thanks in advance.

    • António Ribeiro
      António Ribeiro about 8 years
      Could you please update your answer with your Product class?
    • Kaushi
      Kaushi about 8 years
      @aribeiro I have added the product class in my EDIT.
    • António Ribeiro
      António Ribeiro about 8 years
      Ok, basically you must be facing a dependency conflict. Do you mind posting your pom.xml @Kaushi?
    • Kaushi
      Kaushi about 8 years
      am not using maven as it is causing some issue. so i downloaded the jars and using. pls let me know which version of reateasy-client jar to be used.
    • António Ribeiro
      António Ribeiro about 8 years
      please check my answer and see if it solves your problem.
  • Kaushi
    Kaushi about 8 years
    thanks @aribeiro. u r rite.... finally i have made maven up and added the pom.xml. As you said i have modified the version to resteasy-jaxrs-3.0.12.Final. But now a new error is throwing like java.lang.ClassNotFoundException: org.jboss.resteasy.spi.HeaderValueProcessor
  • António Ribeiro
    António Ribeiro about 8 years
    Then, can you please update your question with the content of your pom.xml?
  • António Ribeiro
    António Ribeiro about 8 years
    @Kaushi, you have two references to resteasy-jaxrs in your pom.xml. You need to remove the last one: 2.2.1.GA.
  • Kaushi
    Kaushi about 8 years
    i removed it and now getting a different error... :( am updating the error in the question
  • António Ribeiro
    António Ribeiro about 8 years
    Why did you remove the resteasy-jaxrs dependency? See my updated answer.
  • Kaushi
    Kaushi about 8 years
  • Kaushi
    Kaushi about 8 years
    if i add those last two dependencies, am getting pom error as Failed to read artifact descriptor for org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.12.Fin‌​al