JAXB xjc工具和非ascii字符
我有一个包含非ascii字符的xsd方案 我想生成类,但强制xjc工具不要将这些字符转换为unicode格式\uxxx,而是保持原样 问题是,当它将unicode表示中的enum值放入生成类的XmlEnumValue注释时,JAXB解组器无法映射适当的字段。当我手动将其转换为纯状态时,它工作正常JAXB xjc工具和非ascii字符,jaxb,xjc,non-ascii-characters,Jaxb,Xjc,Non Ascii Characters,我有一个包含非ascii字符的xsd方案 我想生成类,但强制xjc工具不要将这些字符转换为unicode格式\uxxx,而是保持原样 问题是,当它将unicode表示中的enum值放入生成类的XmlEnumValue注释时,JAXB解组器无法映射适当的字段。当我手动将其转换为纯状态时,它工作正常 有什么建议吗?您可以使用此代码将文件中的字符转换回本机表示形式: import org.apache.commons.io.FileUtils; import org.apache.commons.la
有什么建议吗?您可以使用此代码将文件中的字符转换回本机表示形式:
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
public void convertToNative(String filePath) throws IOException {
File file = new File(filePath);
FileWriter writer = new FileWriter(filePath + ".converted");
try {
String s = FileUtils.readFileToString(file, "utf-8");
s = StringEscapeUtils.unescapeJava(s);
writer.write(s);
} finally {
writer.close();
}
}
您可以使用以下代码将文件中的字符转换回本机表示形式:
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
public void convertToNative(String filePath) throws IOException {
File file = new File(filePath);
FileWriter writer = new FileWriter(filePath + ".converted");
try {
String s = FileUtils.readFileToString(file, "utf-8");
s = StringEscapeUtils.unescapeJava(s);
writer.write(s);
} finally {
writer.close();
}
}