Hi Jussi,
please see in-line....
On 11/18/2010 05:53 PM, jussi_at_lyytinen.org wrote:
> Hi Jakub,
>
> Yes, that's exactly what I mean and I'm also using Jersey at the
> server side.
O.K.
>
> My JSON markup contained attributes because I use inheritance in my
> object model and by default JAXB seems to use the xsi:type attribute
> to represent it. This transcribed xsi:type attribute then caused the
> Jersey client to crash when it was parsing the response. As a
> workaround I'm now using the @XmlElements annotation to force JAXB to
> use tag names to represent inheritance. With this tweak everything
> works fine but this has the drawback that I'm now explicitly defining
> the mapping between a tag name and the corresponding concrete class.
That explains. This will work only for Jettison based and Jersey mapped
notations and only when you enable all involved XML namespaces to be
propagated
into JSON. Namely at least a namespace map with the following value
needs to be used:
Map<String, String> ns2json = new HashMap<String, String>();
ns2json.put("
http://www.w3.org/2001/XMLSchema-instance", "xsi");
There is a test for this in com.sun.jersey.json.impl.InheritanceTest class.
>
> I assume that I'm also discussing with the author of Jersey's
> JsonXmlStreamReader and JsonReaderXmlEvent classes? If this is the
> case, then I would like to repeat my question about the correctness of
> always returning null as the attribute type. I mean the StAX API
> documentation does not mention such possibility and the XML specs say
> that a parser should fallback to CDATA if it does not know better.
The above mentioned classes have not been designed to be fully StAX
compatible and they are also not part of any Jersey API.
You can see them as an implementation detail. The issue you are facing
is caused by the fact XML is using namespaces
while JSON is not.
Anyway, if the above namespace map approach does not solve your issue,
you may try to switch to the POJO mapping feature [1].
HTH,
~Jakub
[1]
http://jersey.java.net/nonav/documentation/latest/json.html#d0e1960
>
> Cheers,
> Jussi
>
>> 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
>
>