Question
· May 4

Problem exporting %Library.DynamicObject to JSON with %JSON.Adaptor

Hello everyone,

I am using a class that inherits from %RegisteredObject and %JSON.Adaptor to generate a JSON string from its instances.

However, one of the properties in my class is of type %Library.DynamicObject, as in the example:

Class Faces.Option Extends (%RegisteredObject, %JSON.Adaptor)
{ 
Property legend As %String;
Property xAxis As %Library.DynamicObject; 
}

When calling %JSONExportToString() on an object of this class, the JSON generated for the xAxis property is incomplete or malformed. It seems the default %JSON.Adaptor doesn't correctly handle properties of type %Library.DynamicObject.

Example of the resulting JSON: {"legend":"test","xAxis": { ... (broken JSON) ...

Previously (in Caché 2018), I used %ZEN.proxyObject for similar situations, but I need a solution for the current versions during migration.

Does anyone know how I can configure %JSON.Adaptor to correctly serialize %Library.DynamicObject properties, or what the recommended approach for this would be?

Thanks!

Product version: IRIS 2024.3
Discussion (1)1
Log in or sign up to continue

When you extend a class with %JSON.Adaptor, you must also ensure that any child classes or classes used as object properties also extend %JSON.Adaptor. Otherwise, you'll encounter an error like:
" ERROR #9411: A class referenced by a %JSONENABLED class must be a subclass of %JSON.Adaptor" during JSON export.

In your case, %DynamicObject/%DynamicArray is a system class that does not extend %JSON.Adaptor, which is why you're unable to export it using methods like %JSONExport, %JSONExportString, or %JSONExportToStream.

To work around this, you can use the Property xAxis As %Library.DynamicObject(%JSONINCLUDE="NONE"); parameter on the problematic field to exclude it from the JSON export.