Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
159
rated 0 times [  166] [ 7]  / answers: 1 / hits: 18363  / 11 Years ago, wed, may 15, 2013, 12:00:00

I am storing a json string into a text field in mysql.
After the insertion, i want to update my json string and add the mysql line id into it with jackson json.



I have a java String which is in Json format



{
thing:val
}


I'm looking to add another K/V without writing lines of codes.



to finally have this :



{
thing:val
mysqlId:10
}


I can convert my String to a JsonNode :



ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree( jsonStr);


Looking to do something like this



json.put(mysqlId,10);
json.toString();


then update in my text field with new json string in mysql



I can't make it.
I don't want use many class is there a simple way to do so with jackson?


More From » java

 Answers
36

Try casting your JsonNode to an com.fasterxml.jackson.databind.node.ObjectNode and then calling put set (or replace) on it.


[#78223] Tuesday, May 14, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckenna

Total Points: 445
Total Questions: 109
Total Answers: 109

Location: Virgin Islands (U.S.)
Member since Sun, May 16, 2021
3 Years ago
;