schemamulesoftbigdecimalfixed-width

Parsing long decimals in Fixedwidth file schema


I have a requirement for parsing a fixedwidth file containing large decimals using MuleSoft. Here's a sample:

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

My schema is working except for the last two fields that are both decimals:

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 }

I'm getting "java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String". It even happens if I reduce both of those fields to length 10 (for troubleshooting purposes).

When I try this for the last two fields:

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

I get :

"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).....

Any ideas on how to parse the very long decimal fields?


Solution

  • The format must be between quotes.

    Example: format: { pattern: '000000000000000000000000.000' }