Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending JSON with arbitrary key values using REST service (Jersey/Jackson)

I want to send something like this from the client to the rest service

jsonObj = 
{
   "info" : {
       "field1" : "val1"..
.....
       "fieldN" : "valN"..
   }
}

And I am not sure how can I handle this using a rest service using

 Jersey and Jackson in Java 

I do not want to create a new info class with using Jackson properties with N field as they are going to change always. I just want to grab the jsonObject which is inside the jsonObject and operate on that as JsonObject.

Any thoughts ?

like image 631
AnujKu Avatar asked Dec 27 '22 05:12

AnujKu


1 Answers

Assuming you have a root object that you are reading the result into, you could define docInfo as a Map<String, Object> within your jsonObj. This will probably work, but I can't give it a go presently.

If you don't have a root object you can just use a Map<String, Object> as your root object and play with it from there. That Map could contain other maps for nested json objects.

like image 116
digitaljoel Avatar answered Jan 14 '23 06:01

digitaljoel