1

I have the following response message in my proto file via NodeJS.

message WorkSpaceResponse{
    google.protobuf.Struct workspace = 1;
}

And below is the service function that sends back the response as:

    let sample = {
        "name": "Test Workspace",
        "id":"sampleId"
    }
    callback(null, { workspace: sample });

However, when the response gets back to the client all I'm getting is the following:

{
  "fields": {}
}

Why is it so, I was expecting the result as

{
  "name": "Test Workspace",
  "id":"sampleId"
}

What am I doing wrong?

ololo
  • 1,326
  • 2
  • 14
  • 47
  • 1
    It's **not** very well documented but here's it documented for Google's Artifact Registry Node.JS SDK [`google.protobuf.Struct`](https://cloud.google.com/nodejs/docs/reference/artifact-registry/latest/artifact-registry/protos.google.protobuf.struct). I think you'll need to [`toObject`](https://cloud.google.com/nodejs/docs/reference/artifact-registry/latest/artifact-registry/protos.google.protobuf.struct#_google_cloud_artifact_registry_protos_google_protobuf_Struct_toObject_member_1_) the response value that you receive from the server to convert the response into a JavaScript object. – DazWilkin Nov 03 '22 at 01:11
  • @DazWilkin Thanks for your suggestion. However, after attempting your suggestion I was greeted with ```response.message.toObject()``` is not a function error. It's so sad they didn't document this for NodeJS. – ololo Nov 03 '22 at 08:13
  • hey, can you please share your code here? how you apply toObject(). kindly share the full code – Suraj Dalvi Jan 19 '23 at 15:16

0 Answers0