users@jersey.java.net

Re: Problem with Jersey Client API and JSON attributes

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 18 Nov 2010 15:40:07 +0100

Hi Jussi,

You probably mean XML attributes transcribed to JSON, as there are no
attributes defined in JSON, correct?

Are you generating the JSON using Jersey on the server side? If so, you
need to configure
the client accordingly to how the server side is configured. If you send
me your server details,
i can try to help you setup the client side.

In any case, a simple reproducible test case would be the most helpful.

Thanks,

~Jakub

On 11/16/2010 04:04 PM, jussi_at_lyytinen.org wrote:
> Hi All,
>
> The Jersey Client API (version 1.4) throws a NullPointerException when
> accessing endpoints using JSON and when the response JSON markup
> contains attributes:
>
> Caused by: java.lang.NullPointerException
> at
> com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.startElement(SAX2DOM.java:212)
> at
> com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.closeStartTag(ToXMLSAXHandler.java:204)
> at
> com.sun.org.apache.xml.internal.serializer.ToSAXHandler.flushPending(ToSAXHandler.java:277)
> at
> com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.startElement(ToXMLSAXHandler.java:646)
> at
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerHandlerImpl.startElement(TransformerHandlerImpl.java:263)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.DomLoader.startElement(DomLoader.java:118)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:481)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:242)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:176)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339)
> at
> com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalJAXBElementFromJSON(BaseJSONUnmarshaller.java:108)
> at
> com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalFromJSON(BaseJSONUnmarshaller.java:97)
> at
> com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.readFrom(JSONRootElementProvider.java:125)
> at
> com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:109)
> at
> com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:552)
> at
> com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:505)
> at com.sun.jersey.api.client.WebResource.handle(WebResource.java:563)
> at
> com.sun.jersey.api.client.WebResource.access$200(WebResource.java:72)
> at
> com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:454)
>
> Quickly looking at this, it would seem that the NullPointerException
> is caused by the fact that the Jersey's
> JsonReaderXmlEvent.getAttributeType(int index) always returns a hard
> coded null. Is this correct? I mean shouldn't it be returning "CDATA"
> instead (as recommended in the section '3.3.3 Attribute-Value
> Normalization' of the XML 1.0 Recommendation)?
>
> If it is correct then I would appreciate any input on how to use the
> Jersey Client API together with endpoints that use JSON attributes.
>
> Thanks,
> Jussi
>