Я работаю с загрузочным приложением Spring и запускаю команду cURL
через терминал,
$ curl -X PUT -H "Content-Type: application/json" -d "{\"status\" : \"false\"}" http://localhost:8080/api/v1/appointments/1
Я получаю ответ повторно,
{"timestamp":"2019-02-08T16:23:32.235+0000","status":400,"error":"Bad Request","message":"JSON parse error: Cannot deserialize instance of java.lang.Boolean out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.Boolean out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]","path":"/api/v1/appointments/1"}
API предоставляетсяниже,
@PutMapping("/{id}")
@JsonDeserialize(as = Boolean.class)
public ResponseEntity<Appointment> updateAppointmentStatus(@PathVariable Long id, @RequestBody Boolean status) {
Appointment appointment = service.findById(id).get();
appointment.setStatus(status);
service.save(appointment);
return ResponseEntity.status(HttpStatus.ACCEPTED).body(appointment);
}
Цель состоит в том, чтобы найти встречу и обновить статус доступности.
Модель также предоставляется,
@Entity
public class Appointment {
// id
// created_at
// appointment_date
// name_of_doctor
// status (Available or Booked)
// price
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
private java.sql.Time craeted_at;
@Column
private java.sql.Date appointment_date;
@Column
private String name_of_doctor;
@Column
@JsonProperty("status")
private Boolean status;
@Column
private double price;
public Appointment() {
}
@JsonCreator
public Appointment(@JsonProperty("craeted_at") Time craeted_at, @JsonProperty("appointment_date") Date appointment_date,
@JsonProperty("name_of_doctor") String name_of_doctor, @JsonProperty("status") boolean status, @JsonProperty("price") double price) {
this.craeted_at = craeted_at;
this.appointment_date = appointment_date;
this.name_of_doctor = name_of_doctor;
this.status = status;
this.price = price;
}
public Appointment(String name_of_doctor, boolean status, double price) {
this.name_of_doctor = name_of_doctor;
this.status = status;
this.price = price;
}
public Appointment(String name_of_doctor, double price) {
this.name_of_doctor = name_of_doctor;
this.price = price;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Time getCraeted_at() {
return craeted_at;
}
public void setCraeted_at(Time craeted_at) {
this.craeted_at = craeted_at;
}
public Date getAppointment_date() {
return appointment_date;
}
public void setAppointment_date(Date appointment_date) {
this.appointment_date = appointment_date;
}
public String getName_of_doctor() {
return name_of_doctor;
}
public void setName_of_doctor(String name_of_doctor) {
this.name_of_doctor = name_of_doctor;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Appointment)) return false;
Appointment that = (Appointment) o;
return isStatus() == that.isStatus() &&
Double.compare(that.getPrice(), getPrice()) == 0 &&
Objects.equals(getId(), that.getId()) &&
Objects.equals(getCraeted_at(), that.getCraeted_at()) &&
Objects.equals(getAppointment_date(), that.getAppointment_date()) &&
Objects.equals(getName_of_doctor(), that.getName_of_doctor());
}
@Override
public int hashCode() {
return Objects.hash(getId(), getCraeted_at(), getAppointment_date(), getName_of_doctor(), isStatus(), getPrice());
}
@Override
public String toString() {
return "Appointment{" +
"id=" + id +
", craeted_at=" + craeted_at +
", appointment_date=" + appointment_date +
", name_of_doctor='" + name_of_doctor + '\'' +
", status=" + status +
", price=" + price +
'}';
}
}
Может кто-нибудь помочьопределить, почему доставляется исключение MismatchedInputException?