Question
· Feb 5, 2016

How to convert JSON to %ListOfDataTypes?

Hi.

It is easy to receive JSON representation or dynamic Array from %ListOfDataTypes:

set l=##class(%ListOfDataTypes).%New()
do l.Insert("a")
do l.Insert("b")
do l.Insert("c")

set arrStr=l.$toJSON()
zwrite arrStr
set arr=l.$compose([])
zwrite arr

How to make backward conversion? How to receive %ListOfDataTypes from dynamic Array an JSON string?

I've tried

SAMPLES>set list = ##class(%ListOfDataTypes).$fromJSON("[""a"",""b"",""c""]")

%FromObject+21^%Library.RegisteredObject.1 *%Exception.General Compose Compose %FromObject Unable to map from %Library.Array instance to %Library.ListOfDataTypes

and

SAMPLES>write arr.$compose(##class(%ListOfDataTypes).%New())
 
zcompose+44^%Library.AbstractObject.1 *%Exception.General Compose Compose %FromObject Unable to map from %Library.Array instance to %Library.ListOfDataTypes
Discussion (3)0
Log in or sign up to continue

This is a new feature, introduced in Caché 2016.2. I am currently investigating whether this is a current limitation or a bug.

Update: %Object can be mapped back to registered objects, but we are missing  a code path for composing a %Array instance into a registered object. Investigation still ongoing, but we are working on it. This code path will be supported in Caché 2016.2.

I will update this comment as soon as the functionality is available in a field test build.

Thank you very much for spotting and reporting!