JSON question - IsNull

Posted by goo on 18-Jun-2019 06:50

I have a check that does something like this:

if theObject:IsNull('myProperty') then ......

But it fails if theObject does not have the property given. I can fix that by adding a check: if theObject:Has('myProperty') and theObject:IsNull('myProperty'), but if I want  to override the method IsNull and add the Has() method into the IsNull, how to do that? Is there better way of doing this?

//Geir Otto

Posted by bronco on 18-Jun-2019 07:15

class TheNewObjectClass inherits TheObjectClass:

 method public override logical IsNull(propertyName as character):

   if (not this-object:Has(propertyName) then

     return true.

   return super:IsNull(propertyName).

 end method.

end class.

// assuming TheObjectClass is the class theObject is an instance of (and isn't final).

// of course now you have to make sure that theObject is of type TheNewObjectClass

All Replies

Posted by bronco on 18-Jun-2019 07:15

class TheNewObjectClass inherits TheObjectClass:

 method public override logical IsNull(propertyName as character):

   if (not this-object:Has(propertyName) then

     return true.

   return super:IsNull(propertyName).

 end method.

end class.

// assuming TheObjectClass is the class theObject is an instance of (and isn't final).

// of course now you have to make sure that theObject is of type TheNewObjectClass

Posted by goo on 18-Jun-2019 07:20
Thanks bronco !!
 
//Geir Otto
 
This thread is closed