In our application one database table having some result stored as json as below:
---------------------------------------------------- -------------
content | other fields...
---------------------------------------------------- --------------
"{ \"key\":[\"value1\",\"value2\",\"value3\"]}" | 12 ...
I need to fetch and write into a result file , the content
field of a set of records as a single json like:
(Expected)
[
{
"content": {
"key": [
"value1",
"value2",
"value3"
]
}
}
.....
]
In the orresponding java entity I put @JsonIgnore
for all fields except content
.
class Result{
//@JsonIgnore
//otherfields
....
@Column("content")
private String content;//the json string field
....
}
But when I read from db and write to file using:
ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
writer.writeValue(new File(outFile), entityList);
I got file as: (Original)
[
{
"content" : "{ \"key\":[\"value1\",\"value2\",\"value3\"]}"
}
....
]
You may notice the issue. It take the jason field as a string and put as the value for the key "content", instead of a nested jason as expected