grpc-ecosystem / grpc-gateway

gRPC to JSON proxy generator following the gRPC HTTP spec

Home Page:https://grpc-ecosystem.github.io/grpc-gateway/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to remove @type or type_url after marshal google.protobuf.Any?

DouFuJuShi opened this issue · comments

How to remove @type or type_url after marshal google.protobuf.Any?

What you're talking about is the proper JSON representation of the google.protobuf.Any type: https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/any.proto#L101-L126. Perhaps you want to use something else?

What you're talking about is the proper JSON representation of the google.protobuf.Any type: https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/any.proto#L101-L126. Perhaps you want to use something else?

In order to return a unified response body, define a messge type and Custom Marshaler :
image

image

Because of google.protobuf.Any,The response json will have @type.
I want to remove @type, how can I do it ?

I see you have a custom marshaler already - you can control exactly what the format is right there.

I strongly suggest not using google.protobuf.Any for responses though. You're losing many of the benefits of protobuf.

I'm going to close this as this is not a support forum for Go and there's nothing the gateway can do about this.