Question
· Nov 8, 2021

Wrong method signature when building REST implementation class using spec

When using the REST API classes for building services on a spec-first approach, the implementation class methods are usually built this format:

ClassMethod <method-name>(body As %DynamicObject) As %Stream.Object

But sometimes it keeps building the endpoint implementation method like this:

ClassMethod <method-name>(body As %Stream.Object) As %DynamicObject

It has been a problem because the rest of my implementation rely on the fact that the "body" object is a DynamicObject.

The REST spec is exactly the same for all endpoints, but this last it built keeps presenting this problem.

Someone has experienced the same issue?

Product version: IRIS 2021.1
Discussion (4)2
Log in or sign up to continue

Marcos,

I was going through some unanswered questions and came across yours. If you could share your spec to DM it to me I can take a look.

However, understand that the %Stream.Object probably contains the JSON payload that you need.  As such you can get your dynamic object with the following command:

set dyObject = {}.%FromJSON(body)

hope that helps.

Welp, this was total user error.  I was trying to read class property that didn't exist.  Also there's some good debugging advice here: Debugging Web | InterSystems Developer Community | CSP|Debugging|Frontend

@Rich Taylor maybe you can help me?

I am passing in a very simple structure in the body of a post request and I'm getting an error returned in Postman saying that the Dynamic Object I'm trying to create from the stream has a property that doesn't exist.

HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
{
    "errors":[ {
            "code":5002,
            "domain":"%ObjectErrors",
            "error":"ERROR #5002: ObjectScript error: <PROPERTY DOES NOT EXIST>

...

Sample data: {"quote_id":2000}

ClassMethod deleteQuote(quote As %Stream.Object) As %DynamicObject

{

    s quoteObj={}.%FromJSON(quote)

    s quoteId=quoteObj."quote_id"

.....

So a few problems:

1) I can't debug this easily . . . I can't pass in a %Stream.Object in VS Code using the debugger and on the command line I can't seem to create a %New() %Stream.Object (my guess is because it's an interface).  Any tips on debugging when you're passing in a stream?

2) The one thing I did do was set my stream data to a global and I'm getting some hints as to what's wrong but I'm not understanding.  A ZW of the global shows me "9430@%Library.DynamicObject" after I have done the %FromJSON() method (I'm pretty sure a global can't store an object so no wonder it's quoted but there's more). If I just save the Read() of the stream to the global then go to the command line and set the string to a variable and then do the {}.%FromJSON(data) method I get the expected data=<OBJECT REFERENCE>[3304@%Library.DynamicObject] and can access the property.

I did notice when using postman, if you 'beautify' the JSON string you get lots of white space and other characters that need to be stripped, so I'm aware that could be a problem, but right now I have the data as a single line with no extra characters.  It's working on the command line when I break it down, but I can't see what the issue is when running the actual POST request.

Any experience with these kinds of issues?