users@jersey.java.net

Re: [Jersey] FW: JaxB Problem

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Wed, 18 Aug 2010 10:09:14 -0700

It does sound like sort of a bug. Underlying secondary issue is that
there are different implementations of QName; some of which accept
nulls (as equivalent to ""), others that do not. I forget which kinds
came from which sources; I think some containers (WebSphere) had
non-standard variant.
I mention this only because it may be tricky to reproduce the issue on
some containers; and that it probably does not affect all users.

But since passing of empty String should always work, it sounds like
code in json-to-stax converter should just convert nulls to empty
Strings.

-+ Tatu +-

On Wed, Aug 18, 2010 at 8:42 AM, Jonathan Cook - FM&T
<Jonathan.Cook2_at_bbc.co.uk> wrote:
> Sent this to the wrong list. Sorry.
>
> Hi,
>
> I'm using Jax-B and sending in a Json request as follows:
>
>         @POST
>         @Consumes("application/json")
>         @Produces("application/json")
>         @Path("property")
>         public Response createOrUpdateConfiguration(ConfigurationItemList
> configItemListRequest){
>                 //log.debug(updateJson);
>                 log.debug(configItemListRequest.getModule());
>         }
>
> This throws an error:
> java.lang.IllegalArgumentException: local part cannot be "null" when
> creating a QName
>         at javax.xml.namespace.QName.<init>(QName.java:246)
>         at javax.xml.namespace.QName.<init>(QName.java:299)
>         at
> com.sun.jersey.json.impl.reader.EndElementEvent.<init>(EndElementEvent.java:51)
>         at
> com.sun.jersey.json.impl.reader.JsonXmlStreamReader.generateEEEvent(JsonXmlStreamReader.java:694)
>         at
> com.sun.jersey.json.impl.reader.JsonXmlStreamReader.readNext(JsonXmlStreamReader.java:371)
>         at
> com.sun.jersey.json.impl.reader.JsonXmlStreamReader.readNext(JsonXmlStreamReader.java:166)
>         at
> com.sun.jersey.json.impl.reader.JsonXmlStreamReader.next(JsonXmlStreamReader.java:429)
>         at
> com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:175)
>         at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:333)
>         at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:312)
>         at
> com.sun.jersey.json.impl.JSONUnmarshaller.unmarshal(JSONUnmarshaller.java:100)
>
> The json I am sending in is valid json:
> {
>     "configurationItemList": [
>         [
>             {
>                 "key": "name",
>                 "value": "dsf"
>             },
>             {
>                 "key": "title",
>                 "value": "sdf"
>             },
>             {
>                 "key": "titlelink",
>                 "value": "sdf"
>             }
>         ]
>     ],
>     "module": "twitter",
>     "sport": "winterolympics"
> }
>
> ConfigurationItemList contains a list of ConfigurationItems which represent
> the key value pairs. I'm not sure what is going wrong. I wondered if there
> was a bug in the version of jersey I am using 1.0.3? Or maybe the array of
> key value pairs needs to be structured differently so it has a name?
>
> If I change to just submitting a string into the POST method then it comes
> in no problem.
>
> Thanks
> Jon