Class Reference
IRIS for UNIX 2019.1
InterSystems: The power behind what matters   
Documentation  Search
  [%SYS] >  [%Library] >  [DynamicAbstractObject]
Private  Storage   

abstract class %Library.DynamicAbstractObject extends %Library.SystemBase

Dynamic Entity base class.

Inventory

Parameters Properties Methods Queries Indices ForeignKeys Triggers
14


Summary

Methods
%FromJSON %FromJSONStats %GetIterator %GetKeyNameMap
%GetObjectType %GetSerial %GetSwizzleObject %GetTypeOf
%OnClose %SetKeyNameMap %SetSerial %Size
%ToJSON

Subclasses
%Library.DynamicArray %Library.DynamicObject

Methods

• classmethod %FromJSON(str) as %DynamicAbstractObject
Given a JSON source, parse the source and return an object of type %DynamicAbstractObject. If an error occurs during parsing, an exception will be thrown.

str The input can be from a number of sources

(1) A string value containing the source.
(2) A stream object to read the source from.
(3) A file URI where the source can be read. The file must be encoded as UTF-8.

Returns An object of type %DynamicAbstractObject containing the parsed JSON.

NOTE: RFC 7159 specifies that the default encoding for JSON values uses UTF-8. This implies that for files and streams not containing 16-bit Unicode it may be necessary to explicitly convert individual character values via a call to $ZCONVERT (e.g. $zcvt(value,"I","UTF8") ) or entire streams by setting the TranslateTable attribute of the stream to "UTF8".

	 
	   set filename = "c:/iscsrc/json/greg4.json"
	   set stream = ##class(%Stream.FileCharacter).%New()
	   set sc = stream.LinkToFile(filename)
	   if ('sc) { w "Error on linking file "_filename,!   q }
	   try {
	       set obj = ##class(%DynamicAbstractObject).%FromJSON(stream)
	   } catch ex {
	       w "Error. Unable to parse file "_filename,!
	       w "Error type   "_ex.Name,!
	       w "Error code   "_ex.Code,!
	       w "Error location "_ex.Location,!
	       set obj = ""
	   }
	   q obj

	   set src = "{""name"" : ""greg"", ""weight"" : 220 }"
	   set obj = ##class(%DynamicAbstractObject).%FromJSON(src)
• classmethod %FromJSONStats(str, stats) as %DynamicAbstractObject
INTERNAL ONLY!

The %FromJSONStats(...) method is for internal use only. The actions taken by this method may change in the future as additional capabilities are added to %DynamicAbstractObject class objects.

• abstract method %GetIterator() as %Iterator.AbstractIterator

Perform an iteration of all the values in a %DynamicAbstractObject subclass.

In the example below, we will output all values contained in a %DynamicArray or a %DynamicObject.

	   set iter = AbstractObject.%GetIterator()
	   while iter.%GetNext(.key , .value ) {
	      write "key = "_key_" , value = "_value,!
	   }
• method %GetKeyNameMap() as %DynamicAbstractObject
INTERNAL ONLY!

The %GetKeyNameMap(keynamemap) method is for internal use only. It returns a copy of the Key Name Map associated with an %DynamicAbstractObject. The formats and semantics of a Key Name Map are known only to the routines and methods that implement the %DynamicAbstractObject class and other Dynamic Entity classes. These formats, semantics, routines and methods may change in the future as additional capabilities are added to %DynamicAbstractObject class objects.

• method %GetObjectType() as %Integer
• method %GetSerial(force As %Integer = 0) as %String
• method %GetSwizzleObject(force As %Integer = 0, ByRef oid As %ObjectIdentity) as %Status
• method %GetTypeOf(key) as %String
Find out the type of value.

Returns One of the following strings are returned.
"null" - JSON null
"boolean" - Either "true" or "false"
"number" - Any numeric value
"oref" - A reference to another object
"object" - A nested object
"array" - A nested array
"string" - Normal text string
"unassigned" - The value is unassigned

• method %OnClose() as %Status
• method %SetKeyNameMap(keynamemap) as %DynamicAbstractObject
INTERNAL ONLY!

The %SetKeyNameMap(keynamemap) method is for internal use only. The actions taken by this method may change in the future as additional capabilities are added to %DynamicAbstractObject class objects.

• classmethod %SetSerial(val As %String) as %Status
• method %Size() as %Integer
Find the size of an %DynamicArray or a %DynamicObject.

Returns An integer showing the size of the array or object. In the case of an array, the size includes unassigned entries within the array. In the case of an object, the size only includes elements that have assigned values.

• method %ToJSON(outstrm As %Stream.Object) as %String
Convert a %DynamicAbstractObject into a JSON string.

outstrm is optional. There are a number of possibilities:
(1) Parameter outstrm is not defined and the method is called via 'DO'. In this case the JSON string is written to the current output device.
(2) Parameter outstrm is not defined and the method is called as an expression. In this case the JSON string becomes the value of the expression.
(3) Parameter outstrm is defined. If it is %Stream object then the JSON string will be written to the stream. If outstrm is present but not an object then it is presumed to be a fully qualified file specification. In that case, a %Stream.FileCharacter stream is created, linked to that file and the JSON string is written to that stream. On completion, this stream is saved. The full path to the file must be defined. If outstrm is an object but is not an instance of %Stream.Object then an exception will be thrown.

NOTE: RFC 7159 specifies that the default encoding for JSON values uses UTF-8. When writing a stream containing 8-bit characters this implies that it may be necessary to explicitly convert individual values via a call to $ZCONVERT (e.g. $zcvt(value,"O","UTF8") ) or entire streams by setting the TranslateTable attribute of the stream to "UTF8"

	set obj = {"title" : "MR" , "lastname" : "JONES"}
	set obj.firstname = "JIMMY"
	do obj.%ToJSON()
	    {"title":"MR","lastname":"JONES","firstname":"JIMMY"}
	set source = obj.%ToJSON()
	write source
	    {"title":"MR","lastname":"JONES","firstname":"JIMMY"}
• private method ConvertStreamToValue(value) as %DynamicAbstractObject
The parameter 'value' must be a %Stream. The contents of 'value' will be placed in a %DynamicCharacter object.

Returns The generated %DynamicString object.



Copyright (c) 2019 by InterSystems Corporation. Cambridge, Massachusetts, U.S.A. All rights reserved. Confidential property of InterSystems Corporation.