You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And then I call the gateway so I get my JSON representation for Nested, I will get {"y":{"x":<some int>}}. What if I want to change how TypeExample is marshaled? Like if I wanted it to become something like this instead
{"y": {"somethingTotallyDifferent": {}}}
Here's the use case: if you try to use GeoJSON with gRPC gateway, it is a terrible mess and it doesn't translate. The geoJSON spec doesn't fit the strict typing for protobuf because geoJSON is a type union
This just doesn't work with protobuf so we are forced to use something like this which is a flat array of point values, which works totally fine for gRPC, but it really falls short for REST clients that want geoJSON. So basically I want to be able to have the REST clients send me geoJSON, then I write a mapping function that turns the geoJSON into the flat array of points which works for my gRPC implementation and keeps me compliant with the geoJSON spec
The text was updated successfully, but these errors were encountered:
Thanks for your issue report. I particularly appreciate that you both outlined the immediate problem and the underlying problem.
To answer your first question, this is possible, but you will need a custom marshaler. What you can do is create a small custom marshaler that wraps the default marshaler, and adds a special case for a specific type at runtime, like so:
To answer the underlying problem, have you explored using the google.protobuf.Struct well known types? This allows arbitrary JSON, but requires more complicated runtime logic. You can use it via the google/protobuf/struct.proto import. Googling will help you find examples. It won't serve you when generating OpenAPI specs but it sounds to me like that's not what you're worried about anyway.
Good luck, and don't hesitate to reach out again if you need more help!
🚀 Feature
Is it possible to hook on a
message
type and have a custom marshal/unmarshal in the gateway? Here's what I mean, if I define:And then I call the gateway so I get my JSON representation for
Nested
, I will get{"y":{"x":<some int>}}
. What if I want to change howTypeExample
is marshaled? Like if I wanted it to become something like this insteadHere's the use case: if you try to use GeoJSON with gRPC gateway, it is a terrible mess and it doesn't translate. The geoJSON spec doesn't fit the strict typing for protobuf because geoJSON is a type union
This just doesn't work with protobuf so we are forced to use something like this which is a flat array of point values, which works totally fine for gRPC, but it really falls short for REST clients that want geoJSON. So basically I want to be able to have the REST clients send me geoJSON, then I write a mapping function that turns the geoJSON into the flat array of points which works for my gRPC implementation and keeps me compliant with the geoJSON spec
The text was updated successfully, but these errors were encountered: