YAMLException: ไม่อนุญาตให้ใช้อักขระพิเศษ

ฉันกำลังพยายามอ่านไฟล์ yml และแปลงเป็นวัตถุเพื่อทำการเปลี่ยนแปลงในไฟล์ yml แต่ได้รับข้อยกเว้นด้านล่างขณะแปลงเมื่อใช้ ISO_8859_1 ในเซิร์ฟเวอร์ linux

ข้อยกเว้น:

Caused by: unacceptable code point 'Â' (0x92) special characters are not allowed
in "'reader'", position 950
        at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:211)
        at org.yaml.snakeyaml.reader.StreamReader.ensureEnoughData(StreamReader.java:176)
        at org.yaml.snakeyaml.reader.StreamReader.peek(StreamReader.java:136)
        at org.yaml.snakeyaml.scanner.ScannerImpl.scanToNextToken(ScannerImpl.java:1185)
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:287)
        at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:227)
        at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:558)
        at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
        at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:168)
        at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:355)
        ... 43 more


com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException: special characters are not allowed
 at [Source: (StringReader); line: 165, column: 40]
        at com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException.from(YAMLException.java:25)
        at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:361)
        at com.fasterxml.jackson.core.JsonParser.nextFieldName(JsonParser.java:825)
        at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:896)
        at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:654)
        at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:895)
        at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:654)
        at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:871)
        at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:654)
        at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:895)
        at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:654)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4014)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3005)

การแยกโค้ด:

StringBuilder contentBuilder = new StringBuilder();
String originalFile = "..path";
try (Stream<String> stream = java.nio.file.Files.lines(Paths.get(originalFile), StandardCharsets.ISO_8859_1)) {
            stream.forEach(s -> contentBuilder.append(s).append("\n"));
        }
        
        Object obj = yamlReader.readValue(contentBuilder.toString(), Object.class); 

เนื้อหา Yaml:

---
spring:
  application:
    name: "DGL-SVC-V-AccountRenewalCD"
cdr:
  enable4IPB: true
  mislogging:
    enabled: true
  paymentFrequency:
    cdUpdate:
      monthly: 1
      endOfTerm: 2
    cdDetails:
      monthly: 0
      endOfTerm: 5
  enable4CPB: false
  enableRetirementCDRenewal: true
  interestPaymentApplicationId: "CA"
  interestDistributionMethod:
    payToAffiliate: 1
    redeposit: 0
  addExternalAccounts: false
  invalidIPBTerms: "1,2"
ccp:
  logger:
    ids:
      templateProperties:
        CDRENEWAL: "com.ccp.logging.ids.formatter.JFPIDSMapper||event-type-ccpids-template-self.ftl"
      emsconnector:
        communication: "jms"
      loggerImplementation: "emsConnector"
hystrix:
  threadpool:
    getCDRatesThreadPoolKey:
      maxQueueSize: 5
      coreSize: 40
      maximumSize: 60
      allowMaximumSizeToDivergeFromCoreSize: true
    getCustomerInfoThreadPoolKey:
      maxQueueSize: 5
      coreSize: 40
      maximumSize: 60
      allowMaximumSizeToDivergeFromCoreSize: true
    validateInternalFundTransferThreadPoolKey:
      maxQueueSize: 5
      coreSize: 40
      maximumSize: 60
      allowMaximumSizeToDivergeFromCoreSize: true
    getCDAccountDetailsThreadPoolKey:
      maxQueueSize: 5
      coreSize: 40
      maximumSize: 60
      allowMaximumSizeToDivergeFromCoreSize: true
    submitCDRenewalThreadPoolKey:
      maxQueueSize: 5
      coreSize: 40
      maximumSize: 60
      allowMaximumSizeToDivergeFromCoreSize: true
    submitInternalFundTransferThreadPoolKey:
      maxQueueSize: 5
      coreSize: 40
      maximumSize: 60
      allowMaximumSizeToDivergeFromCoreSize: true
    getRetirementAccountDetailsThreadPoolKey:
      maxQueueSize: 5
      coreSize: 40
      maximumSize: 60
      allowMaximumSizeToDivergeFromCoreSize: true
    getAccountsThreadPoolKey:
      maxQueueSize: 5
      coreSize: 40
      maximumSize: 60
      allowMaximumSizeToDivergeFromCoreSize: true
  command:
    getRetirementAccountDetails:
      execution.isolation.thread.timeoutInMilliseconds: 10000
    submitCDRenewal:
      execution.isolation.thread.timeoutInMilliseconds: 10000
    submitInternalFundTransfer:
      execution.isolation.thread.timeoutInMilliseconds: 10000
    getCustomerInfo:
      execution.isolation.thread.timeoutInMilliseconds: 10000
    validateInternalFundTransfer:
      execution.isolation.thread.timeoutInMilliseconds: 10000
    getAccounts:
      execution.isolation.thread.timeoutInMilliseconds: 10000
    getCDRates:
      execution.isolation.thread.timeoutInMilliseconds: 10000
    getCDAccountDetails:
      execution.isolation.thread.timeoutInMilliseconds: 1
url-info-config:
  urlInfoMap:
    EXTERNAL_ACCOUNT_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/api/v1/aggregators/customers/{customerId}/accounts"
      serviceName: "B2B-AM-D-YodleeConnector"
      uri: "/api/v1/aggregators/customers/{customerId}/accounts"
      eurekaEnabled: true
    RATES_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/bank/rates/retrieve"
      serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2"
      uri: "/6916/lisa/bank/rates/retrieve"
      eurekaEnabled: true
    CD_ACCOUNT_DETAILS_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/v1/domain/accounts/cdAccountDetails/retrieve"
      serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2"
      uri: "/6916/lisa/v1/domain/accounts/cdAccountDetails/retrieve"
      eurekaEnabled: true
    ACCOUNT_PROFILE_REFRESH_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/private/v2/profiles/accounts/details"
      serviceName: "DGL-AM-V-ACCOUNTPROFILEWS-V2"
      uri: "/private/v1/accounts/profiles/refreshCache"
      eurekaEnabled: true
    ACCOUNT_PROFILE_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/private/v2/profiles/accounts/details"
      serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2"
      uri: "/6916/lisa/private/v1/accounts/profiles"
      eurekaEnabled: true
    PROJECTED_CD_INFO_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/v1/domain/accounts/cdAccountProjectedInfo/retrieve"
      serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2"
      uri: "/6916/lisa/v1/domain/accounts/cdAccountProjectedInfo/retrieve"
      eurekaEnabled: true
    INTERNAL_FUND_TRANSFER_VALIDATE_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/moneymovement/fundstransfer/validate"
      serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2"
      uri: "/6916/lisa/moneymovement/fundstransfer/validate"
      eurekaEnabled: true
    SUBMIT_CD_RENEWAL:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/v1/domain/accounts/updateCDAccount"
      serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2"
      uri: "/6916/lisa/v1/domain/accounts/updateCDAccount"
      eurekaEnabled: true
    CUSTOMER_DEMOGRAPHICS_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/private/v2/profiles/customers/retrieve"
      serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2"
      uri: "/6916/lisa/private/v2/profiles/customers/retrieve"
      eurekaEnabled: true
    INTERNAL_FUND_TRANSFER_SUBMIT_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/moneymovement/fundstransfer/submit"
      serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2"
      uri: "/6916/lisa/moneymovement/fundstransfer/submit"
      eurekaEnabled: true
    RETIREMENT_ACCOUNT_DETAILS_SERVICE:
      fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/v1/retirement/accounts/details/retrieve"
      serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2"
      uri: "/6916/lisa/api/private/v1/retirement/accounts/details/retrieve"
      eurekaEnabled: true
subApp:
  id: "DGL-SVC-V-AccountRenewalCD"
error-info-config:
  errorInfoMap:
    INTERNAL_SERVER_ERROR:
      httpStatus: 500
      errorCode: "INVALID_REQUEST"
      message: "internal server error"
      type: "ERROR"
    NOT_VALID_CD_ACCOUNT:
      httpStatus: 400
      errorCode: "INVALID_CD_ACCOUNT"
      message: "This is not a valid CD Account for Renewal"
      type: "ERROR"
    ST0064:
      httpStatus: 500
      errorCode: "REC_NOT_FOUND"
      message: "RATE REC NOT FOUND FOR"
      type: "ERROR"
    CD_MINIMUM_BALANCE_ERROR:
      httpStatus: 400
      errorCode: "CD_MINIMUM_BALANCE_ERROR"
      message: "Remaining CD balance cannot subceed the CD Minimum Balance."
      type: "ERROR"
    INSUFFICIENT_BALANCE:
      httpStatus: 500
      errorCode: "INSUFFICIENT_BALANCE"
      message: "Insufficient Balance in the Source Account."
      type: "ERROR"
    SP6032:
      httpStatus: 500
      errorCode: "HOLD_ON_ACCOUNT"
      message: "STOP/HOLD ON ACCOUNT"
      type: "ERROR"
    SP6033:
      httpStatus: 500
      errorCode: "NEW_ACCOUNT"
      message: "THIS IS A NEW ACCOUNT"
      type: "ERROR"
    CLOSE_CD_FLOW:
      httpStatus: 500
      errorCode: "CLOSE_CD_FLOW"
      message: "Partial withdrawal amounts must be less than CD account total."
      type: "ERROR"
    SP6014:
      httpStatus: 400
      contentId: "Landing.renewedCdError"
      errorCode: "CUSTOM_ALERT_ERROR"
      message: "Sorry, we can’t process this request.|Your CD renewal request has\
        \ previously been received and is being processed."
      type: "ERROR"
    VALIDATION_ERROR:
      httpStatus: 400
      errorCode: "INVALID_REQUEST"
      message: null
      type: "ERROR"
    TS9400:
      httpStatus: 400
      errorCode: "ACCOUNT_NOT_FOUND"
      message: "RECORD NOT FOUND"
      type: "ERROR"
    NOT_VALID_APP:
      httpStatus: 400
      errorCode: "CUSTOM_ALERT_ERROR"
      message: "Sorry, we can’t process this request on Mobile app at this time.|Please\
        \ retry on online.com."
      type: "ERROR"
    ST7600:
      httpStatus: 500
      errorCode: "CD_ACCT_NOT_FOR_RECIPIENT"
      message: "CD ACCOUNT NOT VALID FOR RECIPIENT"
      type: "ERROR"
    SP6018:
      httpStatus: 400
      contentId: "Landing.renewedCdError"
      errorCode: "CUSTOM_ALERT_ERROR"
      message: "Sorry, we can’t process this request.|Your CD renewal request has\
        \ previously been received and is being processed."
      type: "ERROR"
    ACCOUNT_ALREADY_UPDATED:
      httpStatus: 400
      contentId: "Landing.renewedCdError"
      errorCode: "CUSTOM_ALERT_ERROR"
      message: "Sorry, we can’t process this request.|Your CD renewal request has\
        \ previously been received and is being processed."
      type: "ERROR"
    ST0204:
      httpStatus: 500
      errorCode: "RENEWAL_BEEN_PROCESSED"
      message: "RENEWAL HAS ALREADY BEEN PROCESSED"
      type: "ERROR"
cdr-product-config:
  cdRenewalRetirementProducts:
  - 262
  - 268
  - 269
  cdRenewalProducts:
  - 184
  - 590
  - 591
tmx:
  applicationName:
    android: 154811
    browser: 144564
    ios: 168524

เพิ่มเนื้อหา yaml ตามที่ร้องขอพร้อมกับรายละเอียดข้อยกเว้นและการแยกโค้ด

ความช่วยเหลือใด ๆ ที่ชื่นชม


person Parthiban    schedule 26.10.2020    source แหล่งที่มา
comment
มีอะไรอยู่ในไฟล์ yaml?   -  person Shubham Srivastava    schedule 26.10.2020
comment
เพิ่มเนื้อหา yaml มันเป็นไฟล์ปรับแต่ง   -  person Parthiban    schedule 26.10.2020
comment
ข้อมูลจำเพาะอนุญาตให้ไฟล์ YAML เป็น UTF-8, UTF-16 หรือ UTF-32 ไม่มีอะไรอื่น แม้ว่า Jackson API จะอนุญาตให้คุณใช้การเข้ารหัสอื่นๆ ได้ แต่ฉันขอแนะนำให้ปฏิบัติตามข้อจำกัดนั้นเพื่อหลีกเลี่ยงข้อผิดพลาดเช่นนี้   -  person flyx    schedule 26.10.2020


คำตอบ (1)


ดังที่คุณเห็นที่นี่ และ ที่นี่ จุดโค้ดนี้สอดคล้องกับอักขระเครื่องหมายคำพูดที่ถูกต้องใน windows-1252 อาจเป็นเพราะไฟล์ได้รับการแก้ไข ในระบบ Windows

ตามข้อยกเว้นบ่งชี้ จุดโค้ดนี้ไม่รองรับ iso-8859-1 หรือ utf-8: โปรดดูตัวอย่าง หน้านี้ เพื่อเปรียบเทียบว่าการเข้ารหัสทุกรายการรองรับอักขระนี้และอักขระอื่นๆ อย่างไร

ในการแก้ปัญหาของคุณ เพียงแก้ไขไฟล์และบันทึกเป็นการเข้ารหัส iso-8859-1 หรือ utf-8 แทนที่อักขระนี้ ซึ่งควรจะใช้งานได้ การตรวจสอบไฟล์ YAML ของคุณ เป็นไปได้มากว่าปัญหาจะเกี่ยวข้องกับคำ can’t ที่แตกต่างกันในข้อผิดพลาด messages ของคุณ

person jccampanero    schedule 26.10.2020
comment
ขอบคุณ windows-1252 ใช้งานได้สำหรับฉัน ใช่ ฉันเคยแก้ไขไฟล์ yaml ใน windows pc มาก่อน - person Parthiban; 26.10.2020