User bio

Senior Software Engineer with over a decade of experience working with InterSystems Products.

Member since Apr 27, 2017
Replies:

Hi Jack

IRIS does not provide built-in functionality to generate classes directly from a JSON Schema, unlike the support available for XML Schema (XSD). However, you can programmatically create and compile classes at runtime using the %Dictionary.ClassDefinition API.

Here is the sample code to generate a class.

ClassMethod CreateClass()
{	
	Set clsObj = ##class(%Dictionary.ClassDefinition).%New()
	Set clsObj.Name="Test.NewClass"
	Set clsObj.Super="%RegisteredObject,%JSON.Adaptor"
	Set clsObj.Description="Class created via code"
	Set clsObj.DdlAllowed = 1
	Set clsObj.Inheritance="left"
	
	Set propObj = ##class(%Dictionary.PropertyDefinition).%New()
	Set propObj.Name="Name"
	Set propObj.Type="%String"
	Set propObj.SqlColumnNumber=2
	Do propObj.Parameters.SetAt(70,"MAXLEN")
	
	Set indexObj = ##class(%Dictionary.IndexDefinition).%New()
	Set indexObj.Name="NameIdx"
	Set indexObj.Properties="Name"
	Do clsObj.Properties.Insert(propObj)
	Do clsObj.Indices.Insert( indexObj)
	Set st=  clsObj.%Save()
	D $SYSTEM.OBJ.Compile("Test.NewClass","ckb")
	If $$$ISERR(st) w $SYSTEM.OBJ.DisplayError(st)
}
Open Exchange applications:
Certifications & Credly badges:
Global Masters badges:
Followers:
Following: