0

I have a sample record in oracle DB inside PersonalInformation table having column info[varchar] storing string values in JSON format. i.e :

Row 1.   {"country":"germany"}
Row 2.   {"language":"german"}

Now I want to get the response from a GET API as follows:

response :

 {
"x1" : "value1",

**`"mapMetadata" :{"country":"germany","language":"german"}`** ,

"x3" : "value3"

}

So basically in code I want to covert JsonObject (org.google.GSON.JsonObject) to Map<String, Object> with key as mapMetadata.

I have tried this but not sure how to map it with my key "mapMetadata" and return the response as shown above.

JsonObject jsonObject = JsonParser.parseString(info).getAsJsonObject(); // info is of type String
HashMap<String, Object> yourHashMap = new Gson().fromJson(jsonObject, HashMap.class);

Reference: Convert JSONObject to Map

James Z
  • 12,209
  • 10
  • 24
  • 44
  • Is `info` in the code snippet either `{"country":"germany"}` or `{"language":"german"}`? If so, shouldn't there be at least two variables then? Or what exactly is the value of `info`? – Marcono1234 Oct 04 '22 at 19:15

0 Answers0