本文介绍了JAXB javax.xml.bind.PropertyException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am getting the below error when i try to read XML file that has some japanese characters.

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

package com.jaxb;

package 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();
        }

    }

}



Please advice.

谢谢
Rafi

ThanksRafi

推荐答案

您在 Umarshaller 上设置 Marshaller 属性:

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

您只能设置 Unmarshaller 属性 Unmarshaller

删除 setProperty 然后重试。

这篇关于JAXB javax.xml.bind.PropertyException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 04:32