【发布时间】:2015-06-08 02:13:38
【问题描述】:
这是我的适配器类:
public class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime> {
@Override
public LocalDateTime unmarshal(String v) throws Exception {
return new LocalDateTime(v);
}
@Override
public String marshal(LocalDateTime v) throws Exception {
return v.toString();
}
}
这是一个对象类,我想在其中存储日期:
@XmlAccessorType(XmlAccessType.FIELD)
public class Object {
@XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
private LocalDateTime time;
public LocalDateTime getTime() {
return time;
}
由于某种原因,我无法编译它。它表明问题出在return new LocalDateTime(v);。这是我得到的错误:
Error:(9, 16) java: constructor LocalDateTime in class java.time.LocalDateTime cannot be applied to given types;
required: java.time.LocalDate,java.time.LocalTime
found: java.lang.String
reason: actual and formal argument lists differ in length
和xml部分:
<time type="dateTime">2000-01-01T19:45:00Z</time>
我正在关注this 示例。
【问题讨论】:
-
这个问题很老了,但我还是会问,为了后代:你确定要使用 LocalDateTime 吗?我问的原因是 XML sn-p 包含时区(“Z”,祖鲁语的缩写,基本上是 GMT 的昵称),而 LocalDateTime 不包含时区信息。我想知道:使用 ZoneDateTime 而不是 LocalDateTime 会更合适吗?
标签: java xml datetime jaxb unmarshalling