Hi I am developing a iOS project where I am sending a json array to my REST web services which uses JAVA and Jersey along with Google Gson. I have seen several questions on SO which has similar questions like link but I am not able to get how to approach the solution. here I am sending JSON array to the server which has a structure like
{
"friendList": [
{"id": 1, "username": "user1", "name":"person1"},
{"id": 2, "username": "user2", "name":"person2"},
{"id": 3, "username": "user3", "name":"person3"},...
]
}
Here is my Java Class to consume JSON array
@Path("/FriendsList")
public class RestWebServicesAPI {
@POST
@Path("/friends")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Friends saveFriedList(Friends friend, @Context HttpServletRequest request) {
//What to write here?
return friend;
}
}
- DO I need to create Friends Class and map json objects with the class? please help me with some code.
- What role does GSON can play here if I have to use google gson to map the json to my friends class.
- How can I save the mapped data in mysql database.
any example or any explanation is welcome. thanks