How to ignore serialize a property in a class to JSon
Hi all,
I have a class that I want to serialize to JSon. So I'm using the object %ZEN.Auxiliary.jsonProvider)
set myClass = ##class(myapp.myclass).%New() set myClass.property1 ="value 1" set myClass.property2 = "value 2" set myClass.property3 = "value 3" do ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(.tStream,myClass ,,,1,"ed") write tStream.Read()
By definition of myclass, all properties are serialized, that's fine. But I want not serialize the property3. I think is using a XML attribute in the property, or something about. But I didn't find anything about.
Anyone can help me?
If you use InterSystems IRIS 2019.2 you can extend from %JSON.Adaptor class, which is similar to XML adaptor and allows property parameters to customize serialization behaviour. In your case
%JSONINCLUDE=NONE
%ZEN.Auxiliary.jsonProvider skips % and private properties with some flags. You can use that.
I'm afraid not. I'm using Healthshare Ensemble 2017.2
WOW !!!! IT WORKS !!!!
Thanks for all.
I going to add this method in my utility library
Best regards,
Francisco Lopez
Really nice guys.
I do not have a use for it now, but definitely a really good one
For example so:
Hi Francisco!
Very curious of your utility library - do you want to share some on Open Exchange and Github? )
I'm thinking to create a framework with some utilities for Rest, utils functionst, etc... When it works fine, I'll do
Hi Francisco,
You could take a look at this JSON library for Caché, it has a JSONIGNORE for properties, check the docs folder for more details...
https://github.com/SeanConnelly/Cogs