Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
包级别的XmlJavaTypeAdapter不工作_Java_Jaxb - Fatal编程技术网

包级别的XmlJavaTypeAdapter不工作

包级别的XmlJavaTypeAdapter不工作,java,jaxb,Java,Jaxb,我的包info.java中有以下内容: @XmlJavaTypeAdapters({ @XmlJavaTypeAdapter(type=OffsetDateTime.class, value=OffsetDateTimeAdapter.class) }) package java.time; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.ada

我的
包info.java中有以下内容:

@XmlJavaTypeAdapters({
    @XmlJavaTypeAdapter(type=OffsetDateTime.class, value=OffsetDateTimeAdapter.class)
})
package java.time;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
和以下组件作为适配器:

package java.time;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class OffsetDateTimeAdapter extends XmlAdapter<String, OffsetDateTime> {

    @Override
    public OffsetDateTime unmarshal(String v) throws Exception {
        return OffsetDateTime.parse(v);
    }

    @Override
    public String marshal(OffsetDateTime v) throws Exception {
        return v.toString();
    }
}
package java.time;
导入javax.xml.bind.annotation.adapters.XmlAdapter;
公共类OffsetDateTimeAdapter扩展了XmlAdapter{
@凌驾
public OffsetDateTime解组器(字符串v)引发异常{
返回OffsetDateTime.parse(v);
}
@凌驾
公共字符串封送处理(OffsetDateTime v)引发异常{
return v.toString();
}
}
但当我做以下事情时:

    JAXBContext jc = JAXBContext.newInstance(Root.class);

    Unmarshaller unmarshaller = jc.createUnmarshaller();
    JAXBElement<Root> rootElement = unmarshaller.unmarshal(node, Root.class);
JAXBContext jc=JAXBContext.newInstance(Root.class);
Unmarshaller Unmarshaller=jc.createUnmarshaller();
JAXBElement rootElement=unmarshaller.unmarshal(节点,Root.class);
我得到以下信息:

    JAXBContext jc = JAXBContext.newInstance(Root.class);

    Unmarshaller unmarshaller = jc.createUnmarshaller();
    JAXBElement<Root> rootElement = unmarshaller.unmarshal(node, Root.class);
com.sun.xml.internal.bind.v2.ClassFactory create0信息:在类java.time.OffsetDateTime上找不到默认构造函数


我的设置中是否缺少了一些东西—它没有调用我的适配器?

java。时间不是应该在的包。注释必须引用用户空间中的包和类


将package-info.java和OffsetDateTimeAdapter放入根目录及其子目录所在的包中。

是否尝试向OffsetDateTime类添加空构造函数?@ReneM.-OffsetDateTime是一个JDK类: