users@jersey.java.net

Re: [Jersey] passing in JSON to create a resource

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 30 Jul 2009 15:10:23 +0200

On Jul 30, 2009, at 2:45 PM, Jesus M. Rodriguez wrote:

> Kevin,
>
> On Thu, Jul 30, 2009 at 1:33 AM, Kevin Duffey<andjarnic_at_yahoo.com>
> wrote:
>> Jesus,
>>
>> Take a look at using Jersey with JAXB. It allows you to easily
>> handle json
>> and xml being turned into your domain object and vice versa.
>
> I've got JAXB generating JSON in Jersey for returned objects quite
> nicely.
> But when I have my client POST json to the resource, I get a
> 'java.lang.Error: Error: could not match input' error.
>
> http://pastie.org/565210
>
> So it's saying it doesn't know how to transform my JSON into the
> specified
> object. And I can't find documentation that can clue me into what I'm
> doing wrong.
>

What does the JSON document look like when you return an instance of
MyDomainObject from a GET request ?

It might be that the JSON sent by the client is syntactically invalid,
as the error is occurring in the JSON lexer (it could also be that the
grammar to generate the lexer is incorrect in certain cases).

BTW you can enable logging on the server side to log the requests and
responses so you can compare the JSON returned from a GET request to
the JSON sent by the client for a POST request.

   https://jersey.dev.java.net/nonav/apidocs/1.1.1-ea/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html

Paul.