Serialize data-relations when writing JSON

Posted by onnodehaan on 04-Jun-2017 14:23

Good evening,

I've a question. I have a dataset, that I want to serialize to JSON. Here is a simplified definition:

define temp-table ttMain no-undo serialize-name 'main':U
field Id as character
field Name as character.

define temp-table ttSub no-undo serialize-name 'sub':U
field Id as character
field IdMain as character
field Name as character.

define dataset dsMain for ttMain, ttSub
data-relation drMain for ttMain, ttSub
relation-fields (ttMain.Id, ttSub.IdMain) nested.

This dataset contains one parent table. And one child table. I populate the parent table, but leave the child table empty.

Current result
I than write it out to JSON, which gives me the following:

{"dsMain": {
"main": [
{
"Id": "123",
"NAME": "name"
}
]
}}

Expected result
My problem is, that I'm missing the Sub table. I would have expected the result to be:

{"dsMain": {
"main": [
{
"Id": "123",
"NAME": "name",
"sub" :  [ ]
}
]
}}

I would expected an empty array element for the "sub" table. Since I'm not having one, the external systems runs into errors, because of the missing JSON-node "sub".

Question
Am I right in thinking that this might be a bug in OpenEdge? Of at least something that should be improved? 

Or am I missing something, and can I use a switch, parameter or option to get my expected result?

Regards, Onno

[View:/cfs-file/__key/communityserver-discussions-components-files/19/jsontest.p.txt:0:0]

All Replies

Posted by Mike Fechner on 04-Jun-2017 14:28

Hi Onno, I don't think it's a bug. It's probably intended optimization. But an option to receive the additional empty arrays might be helpful.  

What you can do is write the dataset into a JsonObject and add the missing empty arrays.

Posted by onnodehaan on 04-Jun-2017 14:37

Hi Mike,

Thanks for the fast response. That could be a viable workaround, but my dataset is created dynamically, which makes adding to missing empty arrays less than ideal.

Also, the object that sends out the JSON, is (at the moment) unaware of the missing temp-tables, which requires me to rewrite a fair amount of code.

I still feel it's a bug, because Progresss leaves out information that was intentionally added (the datarelation implies so).

I've just tested the write-xml. It also leaves out the empty table there.

I think I will file a bug report with Progress.

Anyone else on the forum that has experienced this before?

Posted by Mike Fechner on 04-Jun-2017 14:41

Even your dynamic code has all the required information. After the json export of the ProDataset, you still have the dataset - and you just need to check the child-relations of each buffer.

Posted by onnodehaan on 04-Jun-2017 15:29

Hi Mike,

Yes, you are right. it's doable, but I feel it bloats my code more than necessary.

I've used a Java class in another project, that had an option like SetSerializeNull or serializeNulls. That would be a lot easier.

I'll ask Progress for an improvement, because in a world that interacts more and more via (REST-)services, we want to have good tooling and not write those things ourselfs.

Posted by Robin Brown on 06-Jun-2017 06:57

Yes, omitting the empty table from the output is as designed.  You have a viable use case for writing the empty table.  As you say, we could add an argument to include the empty table.  

Regards,

Robin

Posted by onnodehaan on 09-Jun-2017 15:18

Hi Robin,

That would be great! The guys from Support suggested that I wrote an enhancement request.

community.progress.com/.../include_empty_tables_in_the_output_of_write-json_and_write-xml_on_a_dataset

I really feel that it's a great improvement, that shouldn't take an enormous amount of development time to build. It would be great if it would be included in the next OpenEdge 11.7 release.. is that something I can hope for?

Posted by Robin Brown on 12-Jun-2017 07:37

Hi Onno,

Thank you for submitting the enhancement request.  I cannot promise a specific release for this.  While it would be a relatively short development time, we have to consider Dev, QA and Doc resourcing, as well as other work that is currently in our backlog.

Regards,

Robin

Posted by onnodehaan on 12-Jun-2017 07:44

Hi Robin,

I understand... i'm bound by the same chains in my work :-)

But I keep hoping; especially because this enhancement will further future proof building modern integrations with OpenEdge.

Thanks!

This thread is closed