Given is a JSON array
[
{
"ref": "idValue",
"data": {
"filter": [
{
"property": "number"
}
],
"stateId": "contacts"
}
}
]
I store this array as String in a database.
Now I want to embed the given String into a new JSON object, generated dynamically by javax.json.stream.JsonGenerator.
A possible result should look like this:
{
"newValue": "someValue",
"storedFilters": [
{
"ref": "idValue",
"data": {
"filter": [
{
"property": "number"
}
],
"stateId": "contacts"
}
}
]
}
Is there a possibility to achieve this?
My approach:
String jsonStringValue = ... // Contains JSON content of a previous request
HttpServletResponse resp = ...
List<Event> events = ...
OutputStream os = resp.getOutputStream();
Map<String, Boolean> config = new HashMap<String, Boolean>();
if (prettyPrint) {
config.put(JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);
}
JsonGeneratorFactory jgf = Json.createGeneratorFactory(config);
JsonGenerator jg = jgf.createGenerator(os);
if (events.size() > 1) {
jg.writeStartArray();
}
// Some generic stuff happens here which is based on the 'events' list
jg.writeStartObject();
jg.write(JsonConstants.FILTERS, jsonStringValue);
jg.writeEnd();
if (events.size() > 1) {
jg.writeEnd();
}
But this ends up into a field which simply contains the String value in quotes.