Question
Eduard Lebedyuk · Sep 8, 2019

Set NULL in dynamic object

Is there a way to set null in dynamic object without using %Set methods?

I have this method and I need to set NULL as, well, null and not string.

ClassMethod node(name) [ CodeMode = expression ]
{
{
    "name":(name),
    "content":($case(##class(%Dictionary.ClassDefinition).%ExistsId(name), $$$YES:"mycontent", $$$NO:"NULL"))
}
}
0
0 547
Discussion (3)1
Log in or sign up to continue

The short answer is: NO.

The long answer is:

if you try to make a trick, like the below code: it won't work.

ClassMethod name() { 
  set mynull={"def":null}
  set result={"value1":123, "value2":(mynull.def) }
  quit result
 }

now the surprise:

write mynull.%GetTypeOf("def") ---> null
write result.%GetTypeOf("value2") --> string

Yes, because everything you put between parenthesis is evaluated/casted back to COS language, and since there's no NULL in COS, you get an empty string as value and string as its type.

The only way is to have a custom serializer that reads the "null", "false" and "true" and interpret them as it seems fit. This  is how I did by the way.

I know, hence my "...  won't work" comment.