History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-357
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Assignee: Unassigned
Reporter: Bob Herrmann
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XStream

json stuff handles quotes badly

Created: 19/Oct/06 09:00 PM   Updated: 09/Nov/06 05:05 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2.1


 Description  « Hide
XStream xstream = new XStream(new JsonHierarchicalStreamDriver());
System.out.println(xstream.toXML("\"I'm in quotes\" is here"));

is messed up. (can't be parsed by JS) problem is JsonHierarchicalStreamWriter.writeText method doesnt handle quotes well.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Bob Herrmann - 19/Oct/06 09:10 PM
Also try combinations like this;

    String test1 = "\"I start with a quote";
    String test2 = "I end with a quote\"";
    String test3 = " middle \" has quote ";


Bob Herrmann - 19/Oct/06 09:18 PM
In Java5 there is a handy String.replaceAll() method.... Thus JsonHierarchicalStreamWriter.writeText can be written simply as

private void writeText(String text, Class clazz) {
        if (needsQuotes(clazz)) {
            writer.write("\"");
        }
        text = text.replaceAll("\"", "\\\\\"");
        this.writer.write(text);
        if (needsQuotes(clazz)) {
            writer.write("\"");
        }
    }

Joerg Schaible - 20/Oct/06 04:08 PM
This does simply no longer compile on JDK 1.3 ;-)

Joerg Schaible - 20/Oct/06 04:45 PM
Fixed in Subversion. Please report if it works for you.

Joerg Schaible - 09/Nov/06 05:05 PM
Closed as fixed for 1.2.1