Chris Stewart · Mar 29, 2016

Removing properties from a ZENProxyObject before it is returned by a REST service


I have been experimenting with the creation of a set of REST services for an app.  The basic GET operation is set to create a %ZEN.proxyObject instance, and then set an instance of a Persistant class as a property, which gives me all of the values I want to return.  However, it also gives me some values that I don't want to return over REST (because they are both private, and large registered objects which will bog down performance)

How do I remove these values from the ZENproxyObject?  I can only see a full clear() in the documentation, but nothing which can remove individual elements




0 400
Discussion (3)1
Log in or sign up to continue

By default %ToJSON method prints empty properties.

If you pass pFormat without "e" flags (that is passed by default), then empty properties are skipped:

USER>set p = ##class(%ZEN.proxyObject).%New()

USER>set p.a = 1

USER>set p.b = 2

USER>do p.%ToJSON()
USER>set p.b = ""

USER>do p.%ToJSON()
USER>do p.%ToJSON(,"alotw")

I encourage you to use Caché 2016.1 with native JSON support. Don't start with %ZEN.proxyObject.
See great article by Stefan Wittman about JSON support in 2016.1:

There is also this way:

set p = ##class(%ZEN.proxyObject).%New()
set p.a = 1
set p.b = 2
do p.%ToJSON()
kill p.%data("b")
do p.%ToJSON()

kill p.%data("b") would completely remove b property. But better use Caché 2016.1 with native JSON support.

Fantastic.  Thank you both for your help.  I will migrate over to using %Object instead