If you're working on a version of Cache '16.2 or higher (or any version of IRIS) you have access to %DynamicAbstractObject (DAO) and its subclasses %DynamicObject and %DynamicArray. While most people know these classes only as our "in-memory model for JSON" they are actually much more powerful than that. DAO was originally designed to be the basic building block for all forms of abstract data modeling; a staging area, if you will, for Sanitizing, Merging, Annotating, Redacting and Transcoding arbitrary data.
The original vision was that data could be procured from a variety of sources (URLs, result sets, classes, globals, external files, etc.) in a variety of formats (JSON, XML, CSV, YAML, HTML, etc) to populate an Abstract Entity Tree (AET), a directed, but schema-less, graph that focuses on the semantic meaning and core relationships of the data, rather than syntactic artifacts introduced by its serialization. Under the AET model, data is organized into nested trees of _objects_ (unordered collections of named items) and _arrays_ (ordered collections of unnamed items). Individual nodes may be added, edited or removed using the DAO API. Finally, the finished AET (or subtrees thereof) may be published (serialized in a variety of formats) to a stream or persisted to class instances (late-binding schema) or directly to globals (no formal schema required).
DAO currently supports kernel level support for serializing to and from JSON. It also has an API for AET node manipulation and ObjectScript enhancements for initializing nodes directly from JSON-like expressions.
Using DAO, you could build up a single abstract data "document" complete with both meta-data and data to populate a variety of classes and/or globals, serialize this to JSON and import and unpack the payload on the target system (either by importing a file or building a small REST service (JSON travels very well over REST without the overhead of building up a full SOAP/WSDL enterprise - this can be especially useful if working on a prototype, one-off or "actual requirements still in flux" situation).
Out of the box, unfortunately, we do not currently ship many of the other nice to have supporting routines (ResultSetToAET(), XMLToAET(), AETToGlobal(), AETToRegisteredObject(), ValidateToSchema() etc.) but many developers have made such contributions on an ad hoc basis (and some are posted elsewhere on this site).
Also, if you have specific use cases in mind, feel free to contact me, I've prototyped quite a number of DAO type conversion and serialization methods over the years, I may have something that can jumpstart your efforts.
[Note: DAO and its support for %ToJSON() and %FromJSON() is a different beast from the %JSON.Adaptor. The latter works like our XML adaptor and generates methods at class compilation time that write JSON syntax snippets based on the static schema of a %Persistent class. DAO processes ORefs dynamically at run time and has no requirement that classes be "JSON enabled" at compile time, and, as mentioned above, with the right glue code, DAO can also be used to serialize/initialize raw globals, result sets, %Zen.ProxyObjects, streams, %RegisteredObjects, $Lists and ObjectScript multi-dimensionals. ]
Hope this helps.
- Log in to post comments