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

Boon fails to escape double quote #362

Open
dustpuppyNGTI opened this issue Nov 10, 2016 · 0 comments
Open

Boon fails to escape double quote #362

dustpuppyNGTI opened this issue Nov 10, 2016 · 0 comments

Comments

@dustpuppyNGTI
Copy link

dustpuppyNGTI commented Nov 10, 2016

In order to deliver valid JSON double quotes have to be escaped. Boon does not appear to take this into account. There is a setting that does encoding of UTF-8 chars which will also take care of escaping by accident but would push decoding onto the receiving end. There is no way to leave the UTF-8 characters intact but still output escaped double quotes. The Gson parser does the right thing by default:

public class JsonTest {

    public static final Gson GSON_DEFAULT = new Gson();

    public static final ObjectMapper BOON_DEFAULT = JsonFactory.create();
    public static final ObjectMapper BOON_ENCODING = JsonFactory.create(new JsonParserFactory(),
            new JsonSerializerFactory().setEncodeStrings(false));

    private class Wrapper {
        public String test;
    }

    @Test
    public void encodeQuote() {
        Wrapper quote = new Wrapper();
        quote.test = "boe \" aargh";
        Wrapper utf8 = new Wrapper();
        utf8.test = "Τη γλώσσα μου έδωσαν ελληνική";

        System.out.println(GSON_DEFAULT.toJson(quote));
        System.out.println(GSON_DEFAULT.toJson(utf8)+"\n");

        System.out.println(BOON_DEFAULT.toJson(quote));
        System.out.println(BOON_DEFAULT.toJson(utf8)+"\n");

        System.out.println(BOON_ENCODING.toJson(quote));
        System.out.println(BOON_ENCODING.toJson(utf8)+"\n");
    }
}

output:

{"test":"boe \" aargh"}
{"test":"Τη γλώσσα μου έδωσαν ελληνική"}

{"test":"boe \" aargh"}
{"test":"\u03a4\u03b7 \u03b3\u03bb\u03ce\u03c3\u03c3\u03b1 \u03bc\u03bf\u03c5 \u03ad\u03b4\u03c9\u03c3\u03b1\u03bd \u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ae"}

{"test":"boe " aargh"}
{"test":"Τη γλώσσα μου έδωσαν ελληνική"}

EDIT: Checked Jackson too, it behaves like Gson does

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

1 participant