Ich kann JAXB nicht abmelden einen Zeitstempel in einer Rasteasy JAX-RS-Server-Anwendung.jaxb unmarshal timestamp
sieht Meine Klasse wie folgt:
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "foo")
public final class Foo {
// Other fields omitted
@XmlElement(name = "timestamp", required = true)
protected Date timestamp;
public Foo() {}
public Date getTimestamp() {
return timestamp;
}
public String getTimestampAsString() {
return (timestamp != null) ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp) : null;
}
public void setTimestamp(final Date timestamp) {
this.timestamp = timestamp;
}
public void setTimestamp(final String timestampAsString) {
try {
this.timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timestampAsString);
} catch (ParseException ex) {
this.timestamp = null;
}
}
}
Irgendwelche Ideen?
Danke.
Ich habe tatsächlich herausgefunden, wie Sie die Übersetzung mit @ XmlJavaTypeAdapter tun. Dadurch konnte ich verschiedene Java-Klassen, die in meinem Code eine spezielle Behandlung erforderten, anpassen. Vielen Dank. – Ralph
Sie müssen sehr vorsichtig mit SimpleDateformat sein, da es nicht threadsicher ist! Ich bin mir nicht sicher, ob JAXB jedes Mal ein neues Objekt für den Adapter erstellt. –
Weitere Informationen finden Sie unter: http://bdoughan.blogspot.com/2011/01/jaxb-and-datetime-properties.html –