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:34:22 +0200

On Jul 30, 2009, at 3:26 PM, Turner, George wrote:

> Kevin,
>
> You can get this error if you are using a ServiceContextResolver to
> set up the context for how your JSON is created, and a null is
> returned from the following method:
>
> public JAXBContext getContext(Class<?> objectType)
> {
> JAXBContext ctx = null;
> for (Class c : types)
> {
> if (c.equals(objectType))
> {
> ctx = context;
> break;
> }
> }
>
> return ctx;
>
>
> If the class that is trying to be resolved in not in the "types"
> array and ctx is returned as null, you will get the error that you
> are seeing.
>

I am not sure that is the direct cause.

If a JAXBContext is not supplied by the developer via an
implementation of ContextResolver<JAXBContext> then a default
JAXBContext is used, which is the instance created from the class of
the object to marshall/unmarshall.

In this case the error is occurring when initially attempting to parse
the JSON document *before* processing by JAXB occurs. Which is why i
think there is something incorrect about the syntax of the JSON
document.

Paul,


> Gene
>
> -----Original Message-----
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: Thursday, July 30, 2009 07:10
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] passing in JSON to create a resource
>
>
> 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.
>
> ---------------------------------------------------------------------
> 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
>