[Progress Communities] [Progress OpenEdge ABL] Forum Post: JSON reader not working if you have nested temp-tables using the same serialize-name

Status
Not open for further replies.
J

jbijker

Guest
We have a funny situation where we have a dataset with multiple tables, some nested. We use the same SERIALIZE-NAME on the nested tables to keep the format across the tables the same, but this seems to cause problems when doing a READ-JSON. READ-XML seems to work 100%. A simplified test case - we have parent1 and parent2, each with its nested child1 and child2, but we use a serialize-name of child on both of them: DEFINE TEMP-TABLE parent1 NO-UNDO SERIALIZE-NAME "parent1" FIELD cID AS CHARACTER SERIALIZE-NAME "id" FIELD cName AS CHARACTER SERIALIZE-NAME "name". DEFINE TEMP-TABLE parent2 NO-UNDO SERIALIZE-NAME "parent2" FIELD cID AS CHARACTER SERIALIZE-NAME "id" FIELD cName AS CHARACTER SERIALIZE-NAME "name". DEFINE TEMP-TABLE child1 NO-UNDO SERIALIZE-NAME "child" FIELD cID AS CHARACTER SERIALIZE-HIDDEN FIELD cValue AS CHARACTER SERIALIZE-NAME "value". DEFINE TEMP-TABLE child2 NO-UNDO SERIALIZE-NAME "child" FIELD cID AS CHARACTER SERIALIZE-HIDDEN FIELD cValue AS CHARACTER SERIALIZE-NAME "value". DEFINE DATASET dsTest SERIALIZE-NAME "test" FOR parent1, child1, parent2, child2 DATA-RELATION pc1 FOR parent1, child1 RELATION-FIELD(cID, cID) NESTED DATA-RELATION pc2 FOR parent2, child2 RELATION-FIELD(cID, cID) NESTED. DEFINE VARIABLE lcData AS LONGCHAR NO-UNDO. CREATE parent2. ASSIGN parent2.cID = "2" parent2.cName = "parent2". CREATE child2. ASSIGN child2.cID = "2" child2.cValue = "test2". DATASET dsTest:WRITE-JSON("longchar", lcData, TRUE). MESSAGE STRING(lcData) VIEW-AS ALERT-BOX. The JSON that comes back is --------------------------- Message (Press HELP to view stack trace) --------------------------- {"test": { "parent2": [ { "id": "2", "name": "parent2", "child": [ { "value": "test2" } ] } ] }} --------------------------- OK Help --------------------------- Now when I try to read this exact JSON back into the dataset it's not behaving: DEFINE TEMP-TABLE parent1 NO-UNDO SERIALIZE-NAME "parent1" FIELD cID AS CHARACTER SERIALIZE-NAME "id" FIELD cName AS CHARACTER SERIALIZE-NAME "name". DEFINE TEMP-TABLE parent2 NO-UNDO SERIALIZE-NAME "parent2" FIELD cID AS CHARACTER SERIALIZE-NAME "id" FIELD cName AS CHARACTER SERIALIZE-NAME "name". DEFINE TEMP-TABLE child1 NO-UNDO SERIALIZE-NAME "child" FIELD cID AS CHARACTER SERIALIZE-HIDDEN FIELD cValue AS CHARACTER SERIALIZE-NAME "value". DEFINE TEMP-TABLE child2 NO-UNDO SERIALIZE-NAME "child" FIELD cID AS CHARACTER SERIALIZE-HIDDEN FIELD cValue AS CHARACTER SERIALIZE-NAME "value". DEFINE DATASET dsTest SERIALIZE-NAME "test" FOR parent1, child1, parent2, child2 DATA-RELATION pc1 FOR parent1, child1 RELATION-FIELD(cID, cID) NESTED DATA-RELATION pc2 FOR parent2, child2 RELATION-FIELD(cID, cID) NESTED. DEFINE VARIABLE lcData AS LONGCHAR NO-UNDO. lcData = '~{"test": ~{ "parent2": [ ~{ "id": "2", "name": "parent2", "child": [ ~{ "value": "test2" ~} ] ~} ] ~}~}'. DATASET dsTest:READ-JSON("longchar", lcData). FOR EACH parent1: DISPLAY parent1. /* displays nothing, this is correct */ END. FOR EACH child1: DISPLAY child1. /* displays test2 with no id, this is wrong */ END. FOR EACH parent2: DISPLAY parent2. /* displays parent2, this is correct */ END. FOR EACH child2: DISPLAY child2. /* displays nothing, this is wrong */ END. This looks like a bug to me. Anyone has an idea to get past this? We're using OE 11.7.4.

Continue reading...
 
Status
Not open for further replies.
Top