users@jersey.java.net

Fixed in the source <was> Re: [Jersey] Issue with JsonXmlStreamWriter swallowing exceptions <was> Re: [Jersey] Recursive error serializing object

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 26 Oct 2009 09:20:19 +0100

Hi,

I have fixed things in the source (not yet guaranteed to be available
from the repo for 1.1.4-ea-SNAPSHOT and 1.1.5-ea-SNAPSHOT).

I just need ask Jakub about why there is a recursive call here:

     public void writeCharacters(String text) throws
XMLStreamException {
         if (processingStack.get(depth).isNotEmpty) {
             writeStartElement(null, "$", null);
             // TODO why is this a recursive call?
             writeCharacters(text);
             writeEndElement();
         } else {
             try {
                 if (isNonString(processingStack.get(depth -
1).currentName)) {
                      
processingStack.get(depth).writer.write(JsonEncoder.encode(text));
                 } else {
                     processingStack.get(depth).writer.write("\"" +
JsonEncoder.encode(text) + "\"");
                 }
                 processingStack.get(depth).lastWasPrimitive = true;
             } catch (IOException ex) {
                 throw new XMLStreamException(ex);
             }
         }
     }


I think we may be able to remove that as follows:

     public void writeCharacters(String text) throws
XMLStreamException {
         if (processingStack.get(depth).isNotEmpty) {
             writeStartElement(null, "$", null);
             _writeCharacters(text);
             writeEndElement();
         } else {
             _writeCharacters(text);
         }
     }

     public void _writeCharacters(String text) throws
XMLStreamException {
         try {
             if (isNonString(processingStack.get(depth -
1).currentName)) {
                  
processingStack.get(depth).writer.write(JsonEncoder.encode(text));
             } else {
                 processingStack.get(depth).writer.write("\"" +
JsonEncoder.encode(text) + "\"");
             }
             processingStack.get(depth).lastWasPrimitive = true;
         } catch (IOException ex) {
             throw new XMLStreamException(ex);
         }
     }

Paul.


On Oct 23, 2009, at 9:18 PM, Paul Sandoz wrote:

> Hi,
>
> Thanks for the stack trace. That definitely proves it! Thankfully
> this is an easy fix :-)
>
>
> On Oct 23, 2009, at 9:10 PM, Rod Fitzsimmons Frey wrote:
>
>>> One work around is switch to the natural JSON convention. I checked
>>> the StAX writer for that and it does not have the same issue with
>>> exceptions.
>>>
>>> Paul.
>>
>> I'm afraid I don't know what you mean by the natural JSON convention.
>>
>
> See here:
>
> https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/api/json/package-summary.html
>
> https://jersey.dev.java.net/nonav/documentation/1.1.2-ea/user-guide.html
> #d4e579
>
> Note that it might give you slightly different JSON output.
>
> Also Note that there is another issue with enabling the natural JSON
> convention with SE 6 and GlassFish when Jersey is installed with
> GlassFish that we are currently trying to resolve. If you are using
> Tomcat with Jersey jars in the war there should not be an issue.
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>