Question
· Feb 26, 2022

%JSON.Adaptor thow an error with XData with JSON content

Hi Community,

for our forms validation we use XData to describe fields on server side.

These XData are in JSON like this

XData FormValidator [ MimeType = application/json ]
{
 {
  "username": {
   "required": true 
  },
  "email": {
   "datatype": "email"
  }
 }
}

When I try to use %JSON.Adaptor in same classes, IRIS throw an error at compile time

 ERROR #6301: SAX XML Parser Error: invalid document structure while processing Anonymous Stream at line 1 offset 23
  > ERROR #5490: Error running generator for method '%JSONGenerate:helora.worklist.Group'

It looks like method "GenerateMappingFromXdata" from %JSON.Generator try to parse XML only.

Is anyone have a workaround for this ?

Thank you

Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:39:22 EDT [Health:3.3.0]
Discussion (8)1
Log in or sign up to continue

And that's the description

classmethod GenerateMappingFromXdata(class As %String, ByRef mapping) as %Status

Get the JSON adaptor configuration information from class and property parameters.

BUT:
https://docs.intersystems.com/iris20212/csp/documatic/%25CSP.Documatic.cls?&LIBRARY=%25SYS&CLASSNAME=%25JSON.Generator

This class is used internally by InterSystems IRIS. You should not make direct use of it within your applications. There is no guarantee made about either the behavior or future operation of this class.

Hi Robert, 

thank you for your response.

I'm not trying to do JSON mapping.

The XData in my first post is for validating forms server side. We generate methods based on this XData to check if each fields are correctly completed by users. According to this doc : https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls..., we used JSON instead of XML in XData because is easier to parse.

So my XData block is not related to new JSON mapping in IRIS.

When I moved to IRIS, I try to use %JSON.Adaptor in our class instead of Daniel Kutac adaptor (https://github.com/dkutac/cache-json-regular-vs-dynamic-object) to bind/export objects in JSON

For exemple, this class : 

Class helora.worklist.RessourceType Extends (%Persistent, %JSON.Adaptor)
{
Property code As %String;
Property description As %String(MAXLEN = "");
Index codeIdx On code [ Unique ];
XData FormValidator [ MimeType = application/json ] {
{
 "code":  { "required": true }
}
}
}

Does not compile. 

So it looks like impossible to use JSON in XData when classe extends %JSON.Adaptor.