I'm getting an error while passing the parameter 'date' to my java api, the code is the following for the controller:
@RequestMapping(value = "/horario/{fecha}", method = RequestMethod.GET)
@ResponseBody
public Object queryHorariosLibres(@PathVariable("fecha") Date fecha) {
List<Long> horariosLibres = null;
List<Long> turnosTomados = turnoService.getTurnosTomados(fecha);
Calendar dia = new GregorianCalendar();
dia.setTime(fecha);
Horario horario = horarioRepository.findByDia(dia.get(Calendar.DAY_OF_WEEK));
horariosLibres = horario.getHorariosLibres(turnosTomados);
if (horariosLibres == null) {
return "hola";
} else
return horariosLibres;
}
And this is the error I'm getting:
There was an unexpected error (type=Bad Request, status=400).
Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.web.bind.annotation.PathVariable java.util.Date for value '2016-02-15'; nested exception is java.lang.IllegalArgumentException
Here's the code for my model: This is the "horario" class which manages hours :
@Entity
@Table(name = "horario")
public class Horario implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private Integer dia;
private Long horarioInicio;
private Long horarioFin;
Getters And Setter's
@Transient
public List<Long> getHorarios(){
List<Long> horarios = new ArrayList<Long>();
for(Long i = horarioInicio; i <= horarioFin; i+=300){
horarios.add(i);
}
return horarios;
}
@Transient
public List<Long> getHorariosLibres(List<Long> horariosTomados){
List<Long> horariosLibres = getHorarios();
horariosLibres.removeAll(horariosTomados);
return horariosLibres;
}
...
And this is the "turn / schedule" class that manages the appointments:
@Entity
@Table(name = "turno")
public class Turno implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String solicitante;
private String telefono;
private TipoDocumento tipoDocumento;
private String numeroDocumento;
private String email;
private Integer horario;
private String numeroTurno;
private Date fecha;
private String controlFecha;
Getters and Setters
}