Currently, I am saving a JSON string into a text field within a MySQL database. Following the insertion process, my goal is to enhance the JSON string by incorporating the MySQL line ID using Jackson JSON.
Within my Java application, I have a String that is formatted in JSON:
{
"thing":"val"
}
My aim is to include an additional key/value pair without having to write extensive lines of code.
Ultimately, I desire the JSON to look like this:
{
"thing":"val",
"mysqlId":10
}
By leveraging Jackson, I am able to convert my String into a JsonNode:
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree(jsonStr);
I am seeking a method similar to the following:
json.put("mysqlId", 10);
json.toString();
Subsequently, I intend to update the text field in MySQL with the new JSON string.
Despite my efforts, I have been unable to achieve this task. I am looking for a straightforward solution using Jackson without the need for multiple classes. Is there a more simplistic approach available?