Question
· May 16, 2019

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?

Discussion (8)2
Log in or sign up to continue

For example so:

Class myapp.jsonProvider Extends %ZEN.Auxiliary.jsonProvider
{

ClassMethod getOrderedProps(
  pClass As %Dictionary.CompiledClass,
  ByRef pList) [ Internal ]
{
  ##super(pClass,.pList)

  key "" key $o(pList(key))  q:""=key
    zk:$lf(^||skipProps,pList(key)) pList(key)
  }
}

}

Class myapp.myclass Extends %RegisteredObject
{

Property property1 As %String;

Property property2 As %String;

Property property3 As %String;

/// d ##class(myapp.myclass).Test()
ClassMethod Test()
{
  myClass = ..%New()
  myClass.property1 "value 1"
  myClass.property2 "value 2"
  myClass.property3 "value 3"
  
  i=$lb("property3"),$lb("property2","property1"{
    ^||skipProps=i
    ##class(myapp.jsonProvider).%WriteJSONStreamFromObject(.tStream,myClass,,,$$$YES,"ed")
    "skip:",$lts(i),?25," -> ",tStream.Read(),!
  }
}

}

USER>##class(myapp.myclass).Test()
skip:property3            -> {"property1":"value 1","property2":"value 2"}
skip:property2,property1  -> {"property3":"value 3"}