Recently, a partner company started to develop an Angular client for their Cache application. Together, we decided to leverage the power of Caché dynamic objects to exchange JSON encoded data between client and server parts. However, we realized that currently there is a gap in Cache JSON implementation that prevents simple use of traditional registered and persistent classes to exposed their data with the same ease as with XML. I wrote a small JSON adapter, that does the job and bridgers the gap. It's purpose is simple expose data described by a regular Cache class in a one-to-one fashion to a %DynamicObject. On the other hand, when a serialized JSON data comes in, it can be easily deserialized into dynamic object and subsequently bound to regular class by the newly created adapter.

Last comment 18 October 2018
1 8


+ 13


This code snippet uses %ZEN.Auxiliary.jsonSQLProvider. The namespace and string of SQL can be edited for different situations. The class method "test" runs the code:

Class eduardlebedyuk.passQuestionParams
    classmethod test(pValue = 50) {
        s ns = $Namespace
        zn "samples"
        s tSQL = "SELECT ID, Name FROM Sample.Person WHERE Id > ?"
        s tPR = ##class(%ZEN.Auxiliary.jsonSQLProvider).%New()
        s tPR.sql = tSQL
        s tPR.%Format = "tw"
        s tPR.maxRows = 100
        s tParam = ##class(%ZEN.Auxiliary.parameter).%New()
        s tParam.value = pValue
        d tPR.parameters.SetAt(tParam,1)
        d tPR.%DrawJSON() 
        //d ##class(%ZEN.Auxiliary.jsonSQLProvider).%WriteJSONFromSQL(,,,,,tPR)  //same thing
        zn ns

(Originally posted to Intersystems CODE by @Eduard Lebedyuk, 5/13/15)

Here's a link to the code on GitHub

0 2