do I also need the same BookingDTO at the server end for GSON
deserialize it?
Simply put, yes, you'll have to prepare a POJO in order to receive the request. So, for that to happen, JSON deserializer will try to parse the properties off JSON request and map that to a POJO of server.
With Spring, we do stuffs like the following. This is a creating a controller of POST request type expecting to habe a param of BookingDTO
type. We use Jackson library for JSON serialize and deserialize.
@RequestMapping(value = {"/update"}, method = RequestMethod.POST)
@ResponseBody
public void update(@RequestBody BookingDTO bookingDTO) throws FamsException {
// Do what you intend to do with this bookingDTO object sent from client side(Android)
}
As it stands, if your JSON property name matches with the property name and type of BookingDTO
then it can map those and you'll get BookingDTO bookingDTO
object with all the matched properties.
Be sure not to send JSON request with property that isn't in the BookingDTO
POJO. Otherwise, server will throw a 400 BAD REQUEST error.
Note that, you can also send Map
as parameter. This won't require a matching POJO at server side. You can construct a different object by getting the data out of Map the way you like.
Hope you get the idea.