users@jersey.java.net

Re: [Jersey] Entity provider not getting picked up

From: Jaka Jančar <jaka_at_kubje.org>
Date: Mon, 20 Apr 2009 13:33:57 +0200

Ahh, right... I'm not using auto-discovery, so I just added it to
getClasses() of MyAppplication and it works now.

Do you mind me asking, what is the purpose of the @Provider annotation
then? Aren't MessageBody(Reader|Writer) interfaces enough?

On Mon, Apr 20, 2009 at 1:16 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> Hi,
>
> You need to register the provider in the same way as you register a root
> resource class, for example, declare the package where the
> MyEntityProvider.class resides.
>
> When you deploy the application there should be a log of what root resource
> and provider classes have been discovered if you are using the package
> registration configuration.
>
> Paul.
>
> On Apr 20, 2009, at 12:07 PM, Jaka Jančar wrote:
>
>> I have a resource method:
>> --
>> @GET
>> @Produces(MediaType.APPLICATION_JSON)
>> public Object get() {...}
>> --
>>
>> And a custom entity provider:
>>
>> --
>> @Provider
>> @Produces(MediaType.APPLICATION_JSON)
>> @Consumes(MediaType.APPLICATION_JSON)
>> public class MyEntityProvider implements MessageBodyReader<Object>,
>> MessageBodyWriter<Object>
>> --
>>
>> But when invoking the method, the entity provider isn't getting called
>> at all, and I get the exception:
>>
>> --
>> Apr 20, 2009 12:06:19 PM com.sun.jersey.spi.container.ContainerResponse
>> write
>> SEVERE: A message body writer for Java type, class java.lang.Object,
>> and MIME media type, application/json, was not found
>> Apr 20, 2009 12:06:19 PM
>> com.sun.jersey.server.impl.application.WebApplicationImpl onException
>> SEVERE: Internal server error
>> javax.ws.rs.WebApplicationException
>>        at
>> com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:241)
>>        at
>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:689)
>> --
>>
>> Is there anything else I need to do to register it?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>