Finaly "solved" with a call to "Clear" in the generic class.

Method bind(pModel As %DynamicObject, Output sc As %Status = {$$$OK}) [ CodeMode = objectgenerator ]
{
  set kProp = ""
  set prop = %compiledclass.Properties.GetNext(.kProp)
  while kProp '= "" {
    if prop.Collection = "list" {
      do %code.WriteLine(" do .."_prop.Name_".Clear()")
    }
    set prop = %compiledclass.Properties.GetNext(.kProp)
  }
  do %code.WriteLine(" set sc = ..%JSONImport(pModel)")
  do %code.WriteLine(" return")
  return $$$OK
}

Thank you for your inspiration ;-)

Regards

Hi,

exact, with a %New we have a new instance and the list is correctly populated.

The real use case is when we do an update of an existing record (after %OpenId). The expected behaviour is that the list contains the same elements than the array in JSON.

It's also impossible to empty the list with an empty JSON array.

Thanks

Hi,

exact, but the "%JSONImport" is behind a generic REST endpoint wich is used by all of our "Persistent" classes. So I cannot add specific code.

Thanks

Yann Simons · Feb 28, 2022 go to post

Thank you for investigating in IRIS sources.

I'll do a bug report.

Regards

Yann Simons · Feb 27, 2022 go to post

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.cl…, 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.

Yann Simons · Jul 2, 2020 go to post

Here's what I got

-------------- System defaults for I/O tables -------------- 
Table               Name
-----------------   ---------------
Process             RAW
Cache Terminal      UTF8
Other terminal      UTF8
File                RAW
Magtape             RAW
TCP/IP              RAW
System call         RAW
Printer             RAW

Thank you