解析固定宽度文件模式中的长小数

问题描述 投票:0回答:1

我需要使用 MuleSoft 解析包含大小数的固定宽度文件。这是一个示例:

000GX0TEM                        PHN
001GX0TEM                        00001
002GX0TEM                        00001
003GX0TEM                        000010010000100000000001.0000000000000000000000019001.000

我的架构正常工作,除了最后两个字段都是小数:

form: FIXEDWIDTH
structures:
- id: 'INFTEST'
  name: INF Purchase Orders
  data:
  - groupId: 'PO_data'
    count: '>1'
    items:
    - { idRef: 'PO_Header', count: 1 }
    - { idRef: 'PO_Line', count: 1 }
    - { idRef: 'PO_Ship', count: 1 }
    - { idRef: 'PO_Distrib', count: 1 }
segments:
- id: 'PO_Header'
  name: "PO_Header"
  values:
  - { id: 'ROW_ID', type: String, length: 3, tagValue: '000' }
  - { id: 'PO_REF', type: String, length: 30 }
  - { id: 'DISP_METHOD', type: String, length: 3 }
- id: 'PO_Line'
  name: "PO_Line"
  values:
  - { id: 'ROW_ID', type: String, length: 3, tagValue: '001' }
  - { id: 'PO_REF', type: String, length: 30 }
  - { id: 'LINE_NBR', type: String, length: 5 }
- id: 'PO_Ship'
  name: "PO_Ship"
  values:
  - { id: 'ROW_ID', type: String, length: 3, tagValue: '002' }
  - { id: 'PO_REF', type: String, length: 30 }
  - { id: 'LINE_NBR', type: String, length: 5 }
- id: 'PO_Distrib'
  name: "PO_Distrib"
  values: 
  - { id: 'ROW_ID', type: String, length: 3, tagValue: '003' }
  - { id: 'PO_REF', type: String, length: 30 }
  - { id: 'LINE_NBR', type: String, length: 5 }
  - { id: 'SCHED_NBR', type: String, length: 3 }
  - { id: 'DISTRIB_LINE_NUM', type: String, length: 5 }
  - { id: 'QTY_PO', type: Decimal, format: { pattern: 00000000000.0000 }, length: 16 }
  - { id: 'MERCHANDISE_AMT', type: Decimal, format: { pattern: 000000000000000000000000.000 }, length: 28 }

我收到“java.lang.ClassCastException:java.lang.Double 无法转换为 java.lang.String”。如果我将这两个字段的长度减少到 10(出于故障排除目的),甚至会发生这种情况。

当我对最后两个字段尝试此操作时:

  - { id: 'QTY_PO', type: Decimal, format: { pattern: ###########.#### }, length: 16 }
  - { id: 'MERCHANDISE_AMT', type: Decimal, format: { pattern: ########################.### }, length: 28 }

我明白了:

"org.yaml.snakeyaml.v2_0.parser.ParserException - while parsing a flow node
 in 'reader', line 41, column 3:
      - { id: 'MERCHANDISE_AMT', type: ... 
      ^
expected the node content, but found '-'
 in 'reader', line 41, column 3:
      - { id: 'MERCHANDISE_AMT', type: ... 
      ^

while parsing a flow node
 in 'reader', line 41, column 3:
      - { id: 'MERCHANDISE_AMT', type: ... 
      ^
expected the node content, but found '-'
 in 'reader', line 41, column 3:
      - { id: 'MERCHANDISE_AMT', type: ... 
      ^

    at org.yaml.snakeyaml.v2_0.parser.ParserImpl.parseNode(ParserImpl.java:517).....

关于如何解析很长的十进制字段有什么想法吗?

schema mulesoft bigdecimal fixed-width
1个回答
0
投票

格式必须位于引号之间。

示例:

format: { pattern: '000000000000000000000000.000' }

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.