I have an JSF application that stores/retrieves data to/from Oracle DB. Very simple application. I used Gson (from google) API to convert String type data to JSON format into a table in DB.
When I inspected stored data from the table, I expected "{" and "}" beginning and end but I didn't see it instead data was wrapped with double quotes. Is this correct?
Here is an example.
From UI (.xhtml) there is an inputText field to capture data. The data is part (property) of JPA entity model and this model is persisted to DB.
(foo = foo) gson.toJson(variable_that_holds_above_value);
After querying data from the DB, data stored as ... The column that contains below data is clob type.
"(foo \u003d foo)"
"=" is encoded as "\u003d" b/c I didn't use disableHtmlEscaping().
[update]
I realized that gson.toJson() does what it should but what I wanted/expected was "{"keyName":"foo=foo"}. I naively thought simply providing a string to toJson() will do that for me.
I decided to use JsonObject instead. Reading this How to convert a String to JsonObject using gson library helped me.
JsonObject jb = new JsonObject();
jb.addProperty("keyName","foo=foo");