Skip to content

How to JSON Transcode Protos With Naming Equal to Generated Typescript Repeated Fields #1465

Closed
@rauljordan

Description

@rauljordan

📚 Documentation

Hi all, currently I have this protobuf:

message FooResponse {
  repeated int foo = 1;
}

Which gets compiled into the following typescript definition using proto-gen-ts

export class FooResponse extends jspb.Message {
  getFooList(): Array<int>;
  setFooList(value: Array<int>): void;
  clearFooList(): void;
  addFoo(value?: int, index?: number): APIKey;

  serializeBinary(): Uint8Array;
  toObject(includeInstance?: boolean): FooResponse.AsObject;
  static toObject(includeInstance: boolean, msg: FooResponse): FooResponse.AsObject;
  static serializeBinaryToWriter(message: FooResponse, writer: jspb.BinaryWriter): void;
  static deserializeBinary(bytes: Uint8Array): FooResponse;
  static deserializeBinaryFromReader(message: FooResponse, reader: jspb.BinaryReader): FooResponse;
}

export namespace FooResponse {
  export type AsObject = {
    fooList: Array<int>,
  }
}

I want to be able to use this type in my front-end, but the JSON data returned by my grpc-gateway looks like this:

{ foo: [1, 2, 3] }

Instead of the expected

{ fooList: [1, 2, 3] }

Any way around this? Would I need to implement a custom marshaler just to achieve this desired result?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions