gRPC json data in camel case

Viewed 572

I received a json data from gRPC and it is on Pascal case. I want it to be in camel case. I am using angular to access the gRPC service. Even when i serialize and convert the result into camel case, the output in angular is always in Pascal Case. Below are the details.

protobuf message

message EmployeeRecord {
   string record = 1;
}

gRPC service

var serializedResult = JsonConvert.SerializeObject(fields, new JsonSerializerSettings
{
   ContractResolver = new CamelCasePropertyNamesContractResolver()
});

var result = new Protos.EmployeeRecord() { record = serializedResult };

return result;

angular code

public getEmployees() : void{
    this.response = "";
    const service = new EmployeeServiceClient(this.gRPCUrl, null);
    const request = new EmployeeRecord();
    request.setMesssage('');

    service.fields(request, null, (err, response: EmployeeRecord) => {
        if (err) {
          console.log(err);
        }
        else {
          this.response = response.toObject().record;
        }
    });
  }

the result in this.response is always in Pascal Case

2 Answers

You serialize to JSON on your server. Then you send the JSON in a string field of a protobuf message to angular.

It seems very unlikely that the string changes during the transmission.

It is much more likely that your server does not generate the data you expect (check with logging) or that you mixed something up in the client.

I am using the grpcui tool and have noticed a similar issue: the JSON Raw Request uses myExampleFieldName but the correct name is my_example_field_name

Maybe JSON does not allow underscores?

Related