Published on InterSystems Developer Community (https://community.intersystems.com)

Home > REST fromJSON nested structure date not working, getting "Datatype value is not a number" for a date, not possible to debug in Atelier.

Question
Elize VdRiet · Feb 24, 2019

REST fromJSON nested structure date not working, getting "Datatype value is not a number" for a date, not possible to debug in Atelier.

Hi,

I am having a problem in REST service when de-serializing JSON using a nested Property.

I am new to Intersystems and my first time creating REST Service. I setup Atelier dev environment. The worst IDE I have ever worked in. I was able to  attach to a process in the debug perspective and step through the code, but one cannot see contents of variables nor print anything to the console, so it is useless as a debugging tool. When looking at a variable all it displays is its type of the variable and if I try to "watch" I get:

An internal error occurred during: "Label Job".
java.lang.NullPointerException

SO I am unable to solve the issue I am having with the JSON in my REST service due to being unable to debug properly, so I will appreciate any help on this. I try to explain the issue:

I have a Persistent class Consumer which uses 2 SerialObjects as Properties "ActivePeriod" and "AM", I created a REST service to add records to the Consumer, I use Postman to send JSON for a new Consumer.  I get an error back in Postman as follows:

2019-02-01{"Status":"ERROR #7207: Datatype value '2019-02-01' is not a valid number\r\n  > ERROR #5802: Datatype validation failed on property 'Metadata.ActivePeriod:StartDate', with value equal to \"2019-02-01\""}{
    "errors":[ {
            "code":7207,
            "domain":"%ObjectErrors",
            "error":"ERROR #7207: Datatype value '2019-02-01' is not a valid number\r\n  > ERROR #5802: Datatype validation failed on property 'Metadata.ActivePeriod:StartDate', with value equal to \"2019-02-01\"",
            "errors":[ {
                    "code":5802,
                    "domain":"%ObjectErrors",
                    "error":"ERROR #5802: Datatype validation failed on property 'Metadata.ActivePeriod:StartDate', with value equal to \"2019-02-01\"",
                    "id":"DatatypeValidationFailed",
                    "params":["Metadata.ActivePeriod:StartDate","2019-02-01"
                    ]
                }
            ],
            "id":"DTNotNum",
            "params":["2019-02-01"
            ]
        }
    ],
    "summary":"ERROR #7207: Datatype value '2019-02-01' is not a valid number\r\n  > ERROR #5802: Datatype validation failed on property 'Metadata.ActivePeriod:StartDate', with value equal to \"2019-02-01\""
}

The error is on the Consumer's Property "ActivePeriod" (a SerialObject) Property "StartDate". 

I convert the JSON from Postman to DynamicObject and assign it to a new Consumer record, because the ActivePeriod is a Proeprty and StartDate again a property of that, I assign it as follows:

Set consumerRecord.ActivePeriod.StartDate = obj.activePeriod.startDate

The format of the JSON date is "2019-02-01". It seems to be happy with the date of the Proeprty "dateOfBirth" and "DeceasedDateTime", but they are not nested Properties.

There is no clear documention for InterSystems Caché how the Dynamic Object handles nested Properties and how to retrieve it, I cannot see anything wrong in my code.

 

 

 
Here is the full code listing and following that the JSON I sent in Postman:

 

--------------------------------------------------------------------------------------------------

Class Metadata.ActivePeriod Extends %SerialObject
{

Property StartDate As %Date [ InitialExpression = {$ZDate($HOROLOG,3)}, Required ];

/// Set to highest valid value which is 2980013 (December 31, 9999)
Property EndDate As %Date [ InitialExpression = {$ZDate(2980013,3)} ];

Property IsActive As %Boolean [ InitialExpression = {1}, Required ];

/// the Reson changed or deleted text should be used in conjunction with the table <CLASS>HIS.CodeTables.ReasonChangedOrDeleted</CLASS>
Property ReasonChangedOrDeleted As %String(MAXLEN = 100);

}

Class Metadata.AuditMetadata Extends %SerialObject
{

Property CreatedBy As %String;

Property CreatedDateTime As %TimeStamp [ InitialExpression = {$zdatetime($zu(188),3,1,3)} ];

Property ModifiedBy As %String;

Property ModifiedDateTime As %TimeStamp [ InitialExpression = {$zdatetime($zu(188),3,1,3)} ];
}

Class Metadata.CodeBaseDefinition Extends %SerialObject
{

Property Code As %String(MAXLEN = 50);

Property Display As %String(MAXLEN = 100);

Property Definition As %String(MAXLEN = 500);

Property ActivePeriod As ActivePeriod;

}

 

Class Templates.CodeTableTemplate Extends %SerialObject
{

Property CB As Metadata.CodeBaseDefinition;

Property AM As Metadata.AuditMetadata;
}

 

Class CodeTables.BloodGroup Extends (%Persistent,Templates.CodeTableTemplate)

{

// Parent Relationships -------------------------------------------------------
Relationship ConsumerRel As Consumer.Consumer [ Cardinality = many, Inverse = BloodGroupId];

}

 

Class CodeTables.Gender Extends (%Persistent,Templates.CodeTableTemplate)

{
// Parent Relationships -------------------------------------------------------

Relationship ConsumerRel As Consumer.Consumer [ Cardinality = many, Inverse = GenderId];
}

 

Class Consumer.Consumer Extends %Persistent
{

Property FamilyName As %String(MAXLEN=256) [ Required ];

Property FirstNames As %String(MAXLEN=256) [ Required ];

Property DateOfBirth As %Date;

/// Indicate whether the DOB is approximate, if False then it is exact. Default is False.
Property IsDateOfBirthApproximate As %Boolean [ InitialExpression = {0} ];

/// Indicates whether the consumer has passed away (died/expired)
Property IsDeceased As %Boolean [ InitialExpression = {0} ];

/// The date and time on which the consumer expired (died)
Property DeceasedDateTime As %DateTime;

Property ActivePeriod As Metadata.ActivePeriod;

Property AM As Metadata.AuditMetadata;

// Child Relationships --------------------------------------------------------

Relationship BloodGroupId As CodeTables.BloodGroup [ Cardinality = one, Inverse = ConsumerRel];

Relationship GenderId As CodeTables.Gender [ Cardinality = one, Inverse = ConsumerRel];
 

}

 

 

 

Postman JSON:

---------------------

{        
        "familyName":  "Smith",
        "firstNames" : "Peter",
        "dateOfBirth": "1978-10-10",
        "isDateOfBirthApproximate": 0,
        "isDeceased":  false,
        "deceasedDateTime": "",
        "activePeriod": {
            "startDate": "2019-02-01",
            "endDate":   "",
            "isActive":  1,
            "reasonChangedOrDeleted":  ""
        },
        "am": {
            "createdBy": "Elize",
            "createdDateTime": "2019-02-22 03:34:00",
            "modifiedBy": "Elize",
            "modifiedDateTime": "2019-02-22 03:34:00"
        }

}

#Ensemble

Source URL:https://community.intersystems.com/post/rest-fromjson-nested-structure-date-not-working-getting-datatype-value-not-number-date-not