Error producing Json object (urgent help required)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Error producing Json object (urgent help required)

umalkars
Thsi is my code:

@GET
    @Path("getBeanAsObject")
    @Produces(MediaType.APPLICATION_JSON)
    public TestBean sayHtmlHelloBeanObject() {
        TestBean tb = new TestBean();
        tb.setName("My name");
        return tb;
    }

And the TestBean.java is:

@XmlRootElement
public class TestBean implements Serializable {

    private String name;

    public TestBean() {
       
    }
   
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
   
    @Override
    public String toString() {
        return name;
    }
}

I get the following exception:

2012-02-17 09:14:27,437 [http-8080-2] ERROR container.ContainerResponse  - A message body writer for Java class com.test.TestBean, and Java type class com.test.TestBean, and MIME media type application/json was not found
2012-02-17 09:14:27,437 [http-8080-2] ERROR container.ContainerResponse  - The registered message body writers compatible with the MIME media type are:
*/* ->
  com.sun.jersey.core.impl.provider.entity.FormProvider
  com.sun.jersey.core.impl.provider.entity.StringProvider
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider
  com.sun.jersey.core.impl.provider.entity.DataSourceProvider
  com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
  com.sun.jersey.core.impl.provider.entity.ReaderProvider
  com.sun.jersey.core.impl.provider.entity.DocumentProvider
  com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
  com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
  com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
  com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General

Any help appreciated, thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Error producing Json object (urgent help required)

Pavel Bucek-2
Do you have jersey-json module declared as dependency in your pom?

See "json-from-jaxb" sample for more details.
http://search.maven.org/#search|gav|1|g%3A%22com.sun.jersey.samples%22%20AND%20a%3A%22json-from-jaxb%22

Regards,
Pavel

On 2/17/12 4:56 AM, umalkars wrote:

> Thsi is my code:
>
> @GET
>      @Path("getBeanAsObject")
>      @Produces(MediaType.APPLICATION_JSON)
>      public TestBean sayHtmlHelloBeanObject() {
>          TestBean tb = new TestBean();
>          tb.setName("My name");
>          return tb;
>      }
>
> And the TestBean.java is:
>
> @XmlRootElement
> public class TestBean implements Serializable {
>
>      private String name;
>
>      public TestBean() {
>
>      }
>
>      public String getName() {
>          return name;
>      }
>
>      public void setName(String name) {
>          this.name = name;
>      }
>
>      @Override
>      public String toString() {
>          return name;
>      }
> }
>
> I get the following exception:
>
> 2012-02-17 09:14:27,437 [http-8080-2] ERROR container.ContainerResponse  - A
> message body writer for Java class com.test.TestBean, and Java type class
> com.test.TestBean, and MIME media type application/json was not found
> 2012-02-17 09:14:27,437 [http-8080-2] ERROR container.ContainerResponse  -
> The registered message body writers compatible with the MIME media type are:
> */* ->
>    com.sun.jersey.core.impl.provider.entity.FormProvider
>    com.sun.jersey.core.impl.provider.entity.StringProvider
>    com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
>    com.sun.jersey.core.impl.provider.entity.FileProvider
>    com.sun.jersey.core.impl.provider.entity.InputStreamProvider
>    com.sun.jersey.core.impl.provider.entity.DataSourceProvider
>    com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
>    com.sun.jersey.core.impl.provider.entity.ReaderProvider
>    com.sun.jersey.core.impl.provider.entity.DocumentProvider
>    com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
>    com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
>    com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
>    com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
>    com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
>
> Any help appreciated, thanks in advance.
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Error-producing-Json-object-urgent-help-required-tp7293119p7293119.html
> Sent from the Jersey mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: Error producing Json object (urgent help required)

umalkars
Thanks for the reply. Got it working with the following libraries:

asm-3.3.1.jar
jersey-bundle-1.11.jar
jersey-client-1.11.jar
jersey-core-1.11.jar

It's not a Maven project, had to put these Jars in the /lib folder.

Thanks.