##class(%ZEN.Auxiliary.jsonProvider).%ObjectToJSON() don't show %DynamicObject items
Hello everyone,
I created a Class with this 3 properties
Class TestDynamic Extends (%RegisteredObject, %XML.Adaptor)
{
Property number As %xsd.string;
Property exam As %xsd.string;
Property result As list Of %DynamicObject;
}
I'm adding objects to list normally
set objTest=##class(TestDynamic).%New()
set objDynamic={"field":"value"}
do objTest.result.Insert(objDynamic)
But when i use this method to convert to JSON
##class(%ZEN.Auxiliary.jsonProvider).%ObjectToJSON(objTest,,,"aeoqtw")
It doesn't show the items from %DynamicObject just show this:
{
"number": "",
"exam": "",
"result": [
"21@%Library.DynamicObject"
]
}
Cheers.
jsonProvider was invented before native JSON support was added. And there is no reasons to use it already. If you need a JSON representation for an object, look at %JSON.Adaptor
I am using Caché 2018.1.4.505.1 and don't have %JSON.Adaptor class, can I add this class in any way?
You would need to copy %JSON package from the latest IRIS version, but not sure if it will work.
I did this more than a year ago. It was quite some effort but it worked nicely.
But I was blocked by ISC and got under pressure not to publish it for copy-right reasons.
So be careful not to have this same conflict. Pls. don't ask for details!
Hi @Flávio Lúcio Naves Júnior
As Dmitry mentioned, it would be better if you use the %JSON.Adaptor.
Which version are you working with?
I am using Caché 2018.1.4.505.1 and don't have %JSON.Adaptor class
I solved the problem changing the property, I started to use DynamicArray and the method .%ToJSON()