0
我有這樣一個類:無法從字符串值實例類型[簡單類型,類java.time.LocalDate]的價值
@Data
@NoArgsConstructor(force = true)
@AllArgsConstructor(staticName = "of")
public class BusinessPeriodDTO {
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
LocalDate startDate;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
LocalDate endDate;
}
我使用另一個類中這個類,我們稱之爲PurchaseOrder
@Entity
@Data
@NoArgsConstructor(access = AccessLevel.PROTECTED, force = true)
public class PurchaseOrder {
@EmbeddedId
PurchaseOrderID id;
@Embedded
BusinessPeriod rentalPeriod;
public static PurchaseOrder of(PurchaseOrderID id, BusinessPeriod period) {
PurchaseOrder po = new PurchaseOrder();
po.id = id;
po.rentalPeriod = period;
return po;
}
我試圖用jakson填充了一個採購訂單的記錄,這JSON:
{
"_class": "com.rentit.sales.domain.model.PurchaseOrder",
"id": 1,
"rentalPeriod": {
"startDate": "2016-10-10",
"endDate": "2016-12-12"
}
}
但我面臨着一個錯誤:
java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class java.time.LocalDate] from String value ('2016-10-10');
我相信jakson和普及工作正常。
@peeskillet ... –
也許這個答案將幫助您:http://stackoverflow.com/questions/28802544/java-8-localdate-jackson-format – rapasoft