1

Converting XML to JSON through StAXON parser, there are datatype mismatch between Json Schema (expected) and actual Response JSON

For ex: As per Swagger Schema, we are expecting a “String” value for a field but XML to JSON parser gives us “Integer” which is not matching with Swagger/Schema document.

In Swagger/Json Schema accountId type mentioned as String.

"accountId" : {
            "type" : "string",
            "description" : "The Id of the account",
            "readOnly" : true
          }

The XML element value of accountId is: < accountId>123</ accountId> After converting XML to JSON the accountId is: **123** but as per schema our expectation is accountId: **“123”**

Universal parsing logic of XML to JSON:

  1. If the element has only Numbers but starts with Zero: <accountId>0123</accountId> then Json output is: String { accountId : “0123” }
  2. If the element has only Numbers but not starts with Zero: <accountId>123</accountId> then Json output is: Integer { accountId : 123 }
  3. If the element has contains character: <accountName>Abc</ accountName> then Json output is: String { accountName : “Abc”)

It will convert Json as per the data, not with any schema, obviously I didn't feed any schema while parsing Staxon parser.

Is there any way I can change the JSON which should match with the expect Json schema. As per the above scenario I am expecting a String value, it should look at the schema and make the datatype of a field. Note: Don't want to convert all to String as well.

Thanks in advance!!!

Maharajan
  • 11
  • 5

0 Answers0