sbcgua / ajson

Yet another json parser serializer for ABAP
MIT License
50 stars 15 forks source link

JSON to ABAP - Single JSON Document vs JSON Array Issues #186

Open kfowlks opened 1 month ago

kfowlks commented 1 month ago

After updating ZCL_AJSON to version 1.19 we have run into an issue that might be a possible bug in the ZCL_AJSON. In our case we work with student data and return a json payload containing a deep structure student document. We have two methods to get this data. 1) get a single document that contains a deep structure as a single item document or return an array of documents.

Issue: In the working scenario the ZCL_AJSON libs is returning the "email" field as a type C, in the error scenario the libs is returning type H based on if the document is presented as a single json document or an array.

The error we are now getting after the upgrade of ZCL_AJSON is "Unsupported target for value" when we use a single json document.

image

When we use the same json document but placed into an json array the issue is not present. The behavior was only observed after the upgrade

Scenario #1 - Get Student returns a single JSON document which results in an error in processing due to the "email" node. It would seem it's due to the node name "email" being used for both the parent and child node. (See Below)

Scenario #2 - Get Students multiply items - The results are returned as an array of student records in this case the code processes as expected without an issue.

Single document

"email": [
    {
        "identifier": "CAMP",
        "name": "CAMP",
        "description": "Campus",
        "contactType": "CAMP",
        "email": "its.sistester@xxxxx.edu"
    },
    {
        "identifier": "OTHR",
        "name": "OTHR",
        "description": "Other",
        "contactType": "OTHR",
        "email": "its.sistester@xxxxx.edu"
    }
]

}


Array document

        "email": [
            {
                "identifier": "CAMP",
                "name": "CAMP",
                "description": "Campus",
                "contactType": "CAMP",
                "email": "its.sistester@xxxxx.edu"
            },
            {
                "identifier": "OTHR",
                "name": "OTHR",
                "description": "Other",
                "contactType": "OTHR",
                "email": "its.sistester@xxxxx.edu"
            }
        ]
    }
]

}

sbcgua commented 1 month ago

Not sure I understood the issue. What exactly are you doing with this json? Can you help with the UT case? I added a test of how I understand it and it works - #187. So more specific details would be helpful