У меня есть сущности, с которыми я работаю, представленные ниже,
@Entity
public class Product {
@Id
@Column(name = "productId")
private String productId;
@Column(name = "requestTimestamp")
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ", timezone="Europe/Berlin")
private Timestamp requestTimestamp;
@Embedded
private Stock stock;
public Product() {
}
public Product(String productId, Timestamp requestTimestamp, Stock stock) {
this.productId = productId;
this.requestTimestamp = requestTimestamp;
this.stock = stock;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public Timestamp getRequestTimestamp() {
return requestTimestamp;
}
public void setRequestTimestamp(Timestamp requestTimestamp) {
this.requestTimestamp = requestTimestamp;
}
public Stock getStock() {
return stock;
}
public void setStock(Stock stock) {
this.stock = stock;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Product)) return false;
Product product = (Product) o;
return getProductId().equals(product.getProductId()) &&
getRequestTimestamp().equals(product.getRequestTimestamp()) &&
getStock().equals(product.getStock());
}
@Override
public int hashCode() {
return Objects.hash(getProductId(), getRequestTimestamp(), getStock());
}
@Override
public String toString() {
return "Product{" +
"productId='" + productId + '\'' +
", requestTimestamp=" + requestTimestamp +
", stock=" + stock +
'}';
}
}
@Embeddable
public class Stock {
@Column(name = "id")
private String id;
@Column(name = "timestamp")
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ", timezone="Europe/Berlin")
private Timestamp timestamp;
@Column(name = "quantity")
private int quantity;
public Stock() {
}
public Stock(String id, Timestamp timestamp, int quantity) {
this.id = id;
this.timestamp = timestamp;
this.quantity = quantity;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Stock)) return false;
Stock stock = (Stock) o;
return getQuantity() == stock.getQuantity() &&
getId().equals(stock.getId()) &&
getTimestamp().equals(stock.getTimestamp());
}
@Override
public int hashCode() {
return Objects.hash(getId(), getTimestamp(), getQuantity());
}
@Override
public String toString() {
return "Stock{" +
"id='" + id + '\'' +
", timestamp=" + timestamp +
", quantity=" + quantity +
'}';
}
}
Я хотел бы отправить несколько данных в хранилище и использовать для этой цели cURL.
My cURL
Команды:
$ curl -i -X POST -H "Content-Type:application/json" -d "{ \"productId\": \"Apple ID\", \"requestTimestamp\": \"2017-07-16'T'22:54:01.754Z\", \"stock\" : { \"id\": \"Apple ID\", \"timestamp\": \"2000-07-16 22:54:01.754\", \"quantity\": \"250\" }}" http://localhost:8080/api/v1/products/createProduct
Я получаю сообщение об ошибке,
{"timestamp":"2019-03-03T15:53:16.421+0000","status":400,"error":"Bad Request","message":"JSON parse error: Cannot deserialize value of type `java.sql.Timestamp` from String \"2017-07-16'T'22:54:01.754Z\": expected format \"yyyy-MM-dd'T'HH:mm:ss.SSSZ\"; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.sql.Timestamp` from String \"2017-07-16'T'22:54:01.754Z\": expected format \"yyyy-MM-dd'T'HH:mm:ss.SSSZ\"\n at [Source: (PushbackInputStream)
Как мне исправить это?
Это наверняка с меткой времени, как я пытался ранее с@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
и работал нормально.Итак, другая часть приложения хороша, мне просто нужны правильные temrs для запроса cURL.