Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct serialization of google::protobuf::Any #2

Open
tustvold opened this issue Sep 28, 2021 · 5 comments
Open

Correct serialization of google::protobuf::Any #2

tustvold opened this issue Sep 28, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@tustvold
Copy link
Contributor

From https://developers.google.com/protocol-buffers/docs/proto3#json

If the Any contains a value that has a special JSON mapping, it will be converted as follows: {"@type": xxx, "value": yyy}. Otherwise, the value will be converted into a JSON object, and the "@type" field will be inserted to indicate the actual data type.

Currently Any is not special cased and is therefore not serialized/deserialized to/from this custom representation. This should be fixed

@tustvold tustvold added the bug Something isn't working label Sep 28, 2021
@alamb
Copy link
Contributor

alamb commented Dec 16, 2021

For what it is worth, I hit this today as well

Here is an example which might help

pbjson produces:

  "ReadSource": {
    "typeUrl": "type.googleapis.com/com.github.influxdata.idpe.storage.read.ReadSource",
    "value": "COLy2v2h1bG1qwEQl/Gxk7nbhPmzAQ=="
  },

When the binary value in Any is decoded, it looks like

org_id: 12351903361995815266
bucket_id: 12966447011416799383

When I manually changed my pbjson to look like this

  "ReadSource": {
    "@type": "type.googleapis.com/influxdata.platform.storage.read.ReadSource",
    "orgId": "12351903361995815266",
    "bucketId": "12966447011416799383"
  },
...

Then grpcurl was able to handle it

@therishidesai
Copy link

Running into this issue as well with an api that sends the data with the "@type" and unpacked data in the rest of the body. Is there any ideas on how to fix this?

@blinsay
Copy link

blinsay commented Jul 16, 2024

Running into this as well. I'm using pbjson to do some debugging of Envoy types that use Any, and having to manually unwrap Any types is fairly tedious. I'm also generating well-known types as part of prost codegen instead of relying on prost-types, so being able to generate an impl on my own Any` type would be awesome.

@alamb
Copy link
Contributor

alamb commented Jul 16, 2024

If anyone has time to whip up some tests showing what is wrong / what would help that would be swell. A PR to support it would be even better!

@blinsay
Copy link

blinsay commented Jul 19, 2024

Here's a quick test for serialization. I haven't yet tried an implementation.

main...blinsay:pbjson:any-tests

In whipping this up I went to go put together a standalone example repo to try and see how deserialization might work and I fell into a gnarly hole trying to configure well-known types. I think one of the hardest things about support here may be configuring other generated code to use this implementation of Any.

Deserialization seems like it will require some knowledge of existing registered types, and I'm not sure how the whole prost approaches problems like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants