I have to return a JSON formatted object, after fetching the data from the database. Sample database is as below:
I want the JSON returned value to be as:
{
"Name": "Mark",
"Address": {
"Adr1": "123 Avenue",
"Adr2": "Apt-121",
"City": "Phoenix",
"State": "AZ"
}
}
So far, I have been able to fetch the whole address text as a string, which is not useful to me. It looks like this:
{
"Name": "Mark",
"Address": "{Adr1:123 Avenue, Adr2:Apt-121, City:Phoenix, State:AZ}"
}
My POJO looks like:
class Profile{
String name;
Address addr;
}
class Address{
String Adr1;
String Adr2;
String City;
String State;
}
I tried creating a separate class for address, but I am unable to map the individual parameters of Address(Adr1, Adr2, City, State), in order to create the JSON object I need.
Can anyone help me with mapping the correct data from database to JSON ?