The solution presented in Convert a string list/set to json objects in java seems not to work any more.
In version 1.1.4 of the javax.json JSONObject is now a subclass of the typed Map<String, JsonValue>
.
Hence
jsonObject.put("key", "value")
leads to an error, because put expects now an Json Object as the second object.
However, I did not find an easy way to convert a simple String into a JsonValue.
What is the best way to create a simple JsonValue?
Wallenstein
2
Answers
javax.json JSONObject extends Map<String, JsonValue>.
So, you need to convert your String into a JsonValue.
Try this:
You are wrong in that
javax.json.JsonObject
has changed, this is how it always worked in its immutable way. See here for more reference: https://stackoverflow.com/a/26346341/471160, this is from 2014.Since you reference a link to SO question about
jackson
you probably mixed code from two different libraries. If you want code likejsonObject.put("key", "value")
to work then use jackson:or
org.json