0

I am getting error while returning List in RESTFull webservices. My code very similar to this error. enter link description here

Here is POM.xml:

<properties>
    <jersey.version>2.5</jersey.version>
    <mysql.version>5.1.31</mysql.version>
    <hibernate.version>4.3.6.Final</hibernate.version>
    <springframework.version>3.0.5.RELEASE</springframework.version>
</properties>
<dependencies>
<!-- Jersey -->
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>${jersey.version}</version>
</dependency>

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>${jersey.version}</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>${jersey.version}</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.test-framework.providers</groupId>
    <artifactId>jersey-test-framework-provider-inmemory</artifactId>
    <version>${jersey.version}</version>
</dependency>

<!-- Jersey + Spring -->
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>${jersey.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </exclusion>
    </exclusions>
</dependency>

 <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${springframework.version}</version>
    </dependency>

   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
        <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <!--  validation -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.1.3.Final</version>
    </dependency>
    <!-- MySQL -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql.version}</version>
    </dependency>
</dependencies>

My Resource:

 @GET
 @Path("products")
 public List<Product> getProducts() {
    // setting values for my list
    return products;
  }

Error log is:

   org.glassfish.jersey.message.internal.
   MessageBodyProviderNotFoundException:
   MessageBodyWriter not found for media type=text/html, type=class 
    java.util.ArrayList, genericType=java.util.List<com..Product>

Any Help is really appreciated.

Community
  • 1
  • 1
Chowdappa
  • 1,580
  • 1
  • 15
  • 31
  • On top of adding the JSON provider dependency from the duplicate link, you should also annotate your resource method with `@Produces("application/json")`. – Paul Samsotha Jul 14 '16 at 16:47
  • @peeskillet, this is the error if i use @Produces("application/json") MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, – Chowdappa Jul 14 '16 at 16:50
  • 1
    Add the provider dependency in the linked duplicate – Paul Samsotha Jul 14 '16 at 16:52

0 Answers0