Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexOutOfBoundException with JsonWriter.string(value) when value is a String containing JSON #10

Closed
meriouma opened this issue Jan 14, 2014 · 7 comments
Assignees
Milestone

Comments

@meriouma
Copy link

I have a DTO which contains a String json property, which obviously contains JSON (ie : {"json":"{\"key\":\"value\"}"}.

When serializing, I end up with an IndexOutOfBoundsException when calling out.append(value, last, i-last) in method JsonWriter.string(String value)

@meriouma
Copy link
Author

I ended up writing my own JsonSerializer<String> which only does : writer.rawValue("\"" + value.replaceAll("\"", "\\\\\"") + "\"");

@nmorel
Copy link
Owner

nmorel commented Jan 14, 2014

There is also @JsonRawValue that calls writer.rawValue but the characters won't be escaped.

Jackson seems to be able to serialize a string containing json. I'll see what I can do in JsonWriter.

@ghost ghost assigned nmorel Jan 14, 2014
@nmorel
Copy link
Owner

nmorel commented Jan 14, 2014

Found the problem. I took JsonWriter from gson but gson is using java.io.Writer.write(String str, int off, int len) and I replaced it for StringBuilder.append(CharSequence s, int start, int end).
Notice the change in last parameter name, same signature but different meaning. So the compilation was ok but not the behaviour :)

I thought my writer was ok since all the tests from gson were working!

I'll do some more tests and commit a fix. There should be a snpashot version available with the fix by tomorrow.

nmorel added a commit that referenced this issue Jan 14, 2014
@nmorel
Copy link
Owner

nmorel commented Jan 14, 2014

The snapshot should be available. If you need a release version, let me know.

@meriouma
Copy link
Author

Thank you, it works perfectly!

@nmorel
Copy link
Owner

nmorel commented Jan 15, 2014

You're welcome :)

@christiangoudreau
Copy link

Yes, this is needed, if you can release a new version, that would be appreciated! :D

@nmorel nmorel closed this as completed Jan 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants