Serialization behavior in Codeless blocks

Hello!

I am using a 3rd party library in Javascript called node-x12. With this library, I created a few simple API endpoints that I tested in Codeless

The method createInterchange creates a node-x12 interchange object, which is returned and passed to interchangeDebug. I noticed when passing this interchange and referencing it in InterchangeDebug, that methods that are part of the interchange class can no longer be used, and methods like toString use Object.prototype.toString instead of the toString function that the interchange class overrides.

I’m guessing that this is because the object is serialized and deserialized when being passed between methods - I’m curious as to how backendless does this and if there’s a way to preserve the object between codeless blocks?

Hi @braxton_kinney

Each separate API Service ... block runs an HTTP request and uses Content-Type: application/json to transfer data between client and server.
It means when you send any data to the server it converts to JSON string and then the server responds with the same format and then it converts to JS Object.

// on the client
const clientObject = { foo: 123 }
const requestPayload = JSON.stringify(clientObject)

// on the server
// const receivedPayload = requestPayload
// const payload = JSON.parse(receivedPayload) // { foo: 123 }

when it

in your interchangeDebug method need to create a new instance of interchange object based on the received plain object from the client

Regards,
Vlad

1 Like