1

I am using JSONIX to marshall and unmarshall XML received from other system. The XML I want to marshall and unmarshall

<charge> 392.2361
<formatted>392.24</formatted>
</charge>

I still cannot figure out how to unmarshall the value "392.2361". Any one with any idea? Thanks in advance

2 Answers2

0

What you need here is a mixed property.

{
    type: 'classInfo',
    localName: 'MyType',
    propertyInfos: [{
        type: 'elementRef',
        name: 'charge',
        elementName: 'formatted',
        collection : true,
        mixed: true
    }]
}

What you'll as value get is something like:

[ '392.2361', { name: { localPart: 'formatted' }, value: '392.24' }]

Not tested, no guarantees but you get the idea.

lexicore
  • 42,748
  • 17
  • 132
  • 221
0

Finally applied it properly. Thank you #lexicore

Here is my implementation for the mixed property

{
     type: 'classInfo',
     localName: 'ItemizedForDateType', //<date>
     propertyInfos:[
            {
                type: 'element',
                name: 'priceTextType',
                elementName: 'price',
                typeInfo: 'DOTWXML.PriceFormattedType'
            },
            {
                type: 'element',
                name: 'priceMinSellTextType',
                elementName: 'priceMinimumSelling',
                typeInfo: 'DOTWXML.PriceFormattedType'
            }
    ]
},
{
     type: 'classInfo',
     localName: 'PriceFormattedType',                           
     propertyInfos:[
        {
            type: 'elementRef',
            name: 'charge',
            elementName: 'formatted',
            collection : true,
            mixed: true
        },
     ]
}

And the result of unmarshall is something like the following:

    "itemizedForDateType": [
      {
        "TYPE_NAME": "DOTWXML.ItemizedForDateType",
        "priceTextType": {
          "TYPE_NAME": "DOTWXML.PriceFormattedType",
          "charge": [
            "236.8738",
            {
              "name": {
                "namespaceURI": "",
                "localPart": "formatted",
                "prefix": "",
                "key": "formatted",
                "string": "formatted"
              },
              "value": "236.87"
            }
          ]
        }
      }
    ]

I made a mistake by removing "collection : true" and was getting "{}" after unmarshall. Once I realized the "collection : true" was required, put it in the context and everything unmarshalled properly.