Ich habe ein Problem mit der JS Serialisierung von ZonedDateTime
. Wenn es in json konvertiert wird, erzeugt es ein riesiges Objekt und ich möchte nicht, dass alle Daten jedes Mal übertragen werden. Also habe ich versucht, es nach ISO zu formatieren, aber es funktioniert nicht. Wie kann ich es formatieren?Spring Data JPA - ZonedDateTime-Format für JSON-Serialisierung
Hier ist meine Entity Klasse:
@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();
}
}
ich etwas sehr Seltsames hatte: {"Zeit": 1473923145.038000000}. Mit Ihrer Lösung habe ich jetzt {"Zeit": "2016-09-15T07: 57: 26.602 + 0000"} wie gewünscht. –
Für mich reichte es mit registerModule. Ich musste die Entität nicht berühren. Vielen Dank!! –
Ich bekomme immer die Schüttelfrost, wenn jemand eine 5 Zeilen XML aus einer Pom-Datei, Gralde für den Sieg;) –