I would want to POST JSON request using Apache HttpClient. But the Json data is little complex that I would want to send to target system. Below is the json that I would send
{
"name":"xyz",
"id":"428",
"mailId":
[
"mailme@mail.com"
],
"bundle1":
{
"opwarden":
{
"number":"132344345",
"title":"title"
}
}
}
What is the best and easiest way to contract above json data in Java?
With POJOs and ObjectMapper for Jackson:
and Opwarden:
You can create a JSON with:
The output:
I would recommend using JACKSON object mapper. If you dont want to recreate the above model structure writing pojos.
A nice tutorial can be found here enter link description here
You basically use it like this:
Like stated above anyObject could also be a Map key/values and the values can also be maps again.
Your specific use case would be like this: