2
这是我的适配器类:java的解组LocalDateTime错误
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例子。
THX,我通知的日期时间格式它的工作 – Sensei 2015-04-03 01:08:21
我想知道,如果我使用'返回LocalDateTime.parse(v.substring(0,v.length-1));',它也可以。..那有什么区别? – Sensei 2015-04-03 01:09:47
你可以确保'marshal'和'unmarshal'中的相同模式可以。 – 2015-04-03 01:11:51