Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.
Close

#19 Exception in serializing strings with newline to a Writer

2.0.0
closed-fixed
5
2010-10-15
2010-10-15
No

Whenever I try to serialize a string containing a newline (directly or as part of an object I'm serializing) I get an java.lang.StringIndexOutOfBoundsException.

This is a simple code with wich I was able to reproduce the bug:

JSONSerializer ser = new JSONSerializer();
final StringWriter out = new StringWriter();
ser.serialize("A string with a \n newline", out);

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 42
at java.lang.String.substring(String.java:1765)
at java.io.StringWriter.write(StringWriter.java:90)
at flexjson.WriterOutputHandler.write(WriterOutputHandler.java:50)
at flexjson.JSONContext.writeQuoted(JSONContext.java:299)
at flexjson.transformer.StringTransformer.transform(StringTransformer.java:21)
at flexjson.transformer.TransformerWrapper.transform(TransformerWrapper.java:22)
at flexjson.JSONContext.transform(JSONContext.java:75)
at flexjson.JSONSerializer.serialize(JSONSerializer.java:378)
at flexjson.JSONSerializer.serialize(JSONSerializer.java:249)
at Test.main(Dummy.java:30)

Discussion

  • Andrea Polci

    Andrea Polci - 2010-10-15

    Proposed patch

     
  • Andrea Polci

    Andrea Polci - 2010-10-15

    I was able to trak the problem in WriterOutputHandler and I think I solved it.
    I attached a patch with my solution.

     
  • Charlie Hubbard

    Charlie Hubbard - 2010-10-15

    Thanks for submitting this bug. I was able to reproduce this bug, and confirm your patch fixed it after applying it. I'll be fixing this in the next release 2.1 which I've been meaning to release here now, but I keep getting small bug fixes in the from the field like this one that I want to include.

     
  • Charlie Hubbard

    Charlie Hubbard - 2010-10-15
    • status: open --> closed-fixed
     

Log in to post a comment.