JAXB javax.xml.bind.PropertyException

时间:2011-08-23 10:33:36

标签: jaxb

当我尝试读取具有一些日文字符的XML文件时,我收到以下错误。

javax.xml.bind.PropertyException: jaxb.encoding
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.getProperty(AbstractUnmarshallerImpl.java:360)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.getProperty(UnmarshallerImpl.java:423)
at com.jaxb.JAXBTest.main(JAXBTest.java:23)
enter code here

包com.jaxb;

import java.io.FileReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

public class JAXBTest 
{
    public static void main(String args[])
    {

        try
        {
            JAXBContext context = JAXBContext.newInstance(com.pain.jaxb.ver2.Document.class);           
            Unmarshaller um = context.createUnmarshaller();         
            um.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");          
            com.pain.jaxb.ver2.Document PainTransferList2 = (com.pain.jaxb.ver2.Document) um.unmarshal(new FileReader("C:/WorkArea/JAXB/src/com/pain/messages/APXSEPAS_510812_1.XML"));         

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

    }

}

请建议。

由于 拉菲

1 个答案:

答案 0 :(得分:5)

您在Marshaller上设置了Umarshaller媒体资源:

Unmarshaller um = context.createUnmarshaller();         
um.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); 

您只能在Unmarshaller上设置Unmarshaller属性。

删除setProperty,然后重试。