在将 YML 解析为 POJO 时出现异常无效的 UTF-8 起始字节 0x80(在 char #158,字节 #-1)
while parsing YML to POJO getting exception Invalid UTF-8 start byte 0x80 (at char #158, byte #-1)
我正在尝试将 yaml 文件解析为 java 对象,同时解析带有对象映射器的 yaml 文件出现以下异常。
Exception in thread "main"
com.fasterxml.jackson.dataformat.yaml.JacksonYAMLParseException:
java.io.CharConversionException: Invalid UTF-8 start byte 0x80 (at
char #158, byte #-1) at [Source: (File); line: 1, column: 1] at
com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:361)
at
com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4620)
at
com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4469)
at
com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3299)
我的java代码
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
XmlConverterProp prop = objectMapper.readValue(configFile, XmlConverterProp.class);
yml 文件
dateFormat: "MM/dd/yyyy=Billing_Date"
lineItemRowNodeName: row
lineItemsNodeName: Mode_Items
removeValueChars: "Net_Amount=$,Unit_Price=Rs.,Item_Amount=€,Gross_Amount=$"
requiredHeaderTags: "cc_BatchDetails,Invoice_Number,Invoice_Date,PO_Number,Document_Type,Vendor_Name,Tax_Amount,Net_Amount,Invoice_Amount,Currency,Gross_Amount,cc_ProfileName,Remit_To_Address_1"
requiredLineTags: "Item_Code,Item_Description,Quantity,Unit_Price,Item_Amount"
有问题的字符是欧元符号。您的输入未编码为 UTF-8,因为欧元符号编码为 0x80
。这对应于IEC_8859-15 (Latin-9) or Windows-1252.
YAML 要求输入是 UTF 编码之一(8、16 或 32),最常见的是 UTF-8。您需要使用 UTF-8 或其他格式之一对您的 YAML 文件进行编码,以便正确加载。所有代码编辑器都提供了执行此操作的方法,大多数在底部状态栏中都有该选项。
我正在尝试将 yaml 文件解析为 java 对象,同时解析带有对象映射器的 yaml 文件出现以下异常。
Exception in thread "main" com.fasterxml.jackson.dataformat.yaml.JacksonYAMLParseException: java.io.CharConversionException: Invalid UTF-8 start byte 0x80 (at char #158, byte #-1) at [Source: (File); line: 1, column: 1] at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:361) at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4620) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4469) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3299)
我的java代码
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
XmlConverterProp prop = objectMapper.readValue(configFile, XmlConverterProp.class);
yml 文件
dateFormat: "MM/dd/yyyy=Billing_Date"
lineItemRowNodeName: row
lineItemsNodeName: Mode_Items
removeValueChars: "Net_Amount=$,Unit_Price=Rs.,Item_Amount=€,Gross_Amount=$"
requiredHeaderTags: "cc_BatchDetails,Invoice_Number,Invoice_Date,PO_Number,Document_Type,Vendor_Name,Tax_Amount,Net_Amount,Invoice_Amount,Currency,Gross_Amount,cc_ProfileName,Remit_To_Address_1"
requiredLineTags: "Item_Code,Item_Description,Quantity,Unit_Price,Item_Amount"
有问题的字符是欧元符号。您的输入未编码为 UTF-8,因为欧元符号编码为 0x80
。这对应于IEC_8859-15 (Latin-9) or Windows-1252.
YAML 要求输入是 UTF 编码之一(8、16 或 32),最常见的是 UTF-8。您需要使用 UTF-8 或其他格式之一对您的 YAML 文件进行编码,以便正确加载。所有代码编辑器都提供了执行此操作的方法,大多数在底部状态栏中都有该选项。