I've been working on a Spring RESTful application consumed from an Android device. My problem occurs when I'm trying to send a POST request. My object is received on the server side but all the attributes are null.
My Controller :
@Controller
public class BeanController {
@Autowired
private ReservationService reservationService;
@RequestMapping(value = "reservation/add/{dateR}", method = RequestMethod.POST)
public ModelAndView addReservation(@RequestBody Reservation reservation, @PathVariable String dateR) {
Date date = Date.valueOf(dateR);
boolean result = reservationService.saveReservation(reservation,date);
return new ModelAndView("beanXmlView", BindingResult.MODEL_KEY_PREFIX + "reservation", result);
}
}
On my client side I make sure the object attributes are set.
My Client Side :
Reservation reservation = new Reservation();
reservation.setDateReservation(Model.date);
reservation.setSalle(Model.salle);
if(Model.selectedEquipements.size() == 0)
reservation.setEquipements(new ArrayList<Equipement>());
else reservation.setEquipements(Model.selectedEquipements);
reservation.setPlagesHoraires(Model.selectedPlageHoraires);
reservation.setUtilisateur(user);
final String url = "http://10.0.2.2:8080/HibernateSpringREST/";
RestTemplate restTemplate = new RestTemplate();
// Add the Jackson and String message converters
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());
// Make the HTTP POST request, marshaling the request to JSON, and the response to a String
restTemplate.postForObject(url + "reservation/add/"+Model.date, reservation, Reservation.class);
Does any one have an idea about what might be causing this issue ?