Tôi gặp sự cố với việc tuần tự hóa json là ZonedDateTime
. Khi chuyển đổi thành json, nó tạo ra một đối tượng khổng lồ và tôi không muốn tất cả dữ liệu đó được truyền đi mỗi lần. Vì vậy, tôi đã cố định dạng nó thành ISO nhưng nó không hoạt động. Làm thế nào tôi có thể làm cho nó để định dạng?Dữ liệu mùa xuân JPA - Định dạng ZonedDateTime để tuần tự hóa json
Đây là Entity Lớp tôi:
@MappedSuperclass
public abstract class AuditBase {
@Id
@GeneratedValue
private Long id;
@CreatedDate
private ZonedDateTime createdDate;
@LastModifiedDate
private ZonedDateTime lastModifiedDate;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
public ZonedDateTime getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(ZonedDateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
public ZonedDateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(ZonedDateTime createdDate) {
this.createdDate = createdDate;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@PrePersist
public void prePersist() {
this.createdDate = ZonedDateTime.now();
this.lastModifiedDate = ZonedDateTime.now();
}
@PreUpdate
public void preUpdate() {
this.lastModifiedDate = ZonedDateTime.now();
}
}
Tôi có một cái gì đó rất lạ: {"thời gian": 1473923145.038000000}. Với giải pháp của bạn, tôi hiện có {"thời gian": "2016-09-15T07: 57: 26.602 + 0000"} như mong muốn. –
Đối với tôi, nó đã đủ với registerModule. Tôi không phải chạm vào thực thể. Cảm ơn!! –
Tôi luôn cảm thấy ớn lạnh khi một số người đăng 5 dòng XML từ một tệp pom, Gralde để giành chiến thắng;) –