protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.74k stars 15.51k forks source link

[Proposal] [CSharp] Add extension point to allow custom json #17520

Open bsagal opened 3 months ago

bsagal commented 3 months ago

What language does this apply to? CSharp

Describe the problem you are trying to solve. The system I manage needs to handle protobuf messages encoded in JSON. Some of these messages contain byte fields encoded as hex strings instead of the standard base64 format. These fields are identified using options specified in the proto file.

The current Google.Protobuf library cannot handle these messages effectively.

Describe the solution you'd like

Describe alternatives you've considered An alternative approach involves using an external JSON parser to parse these JSON-formatted protobuf messages and manually constructing protobuf message objects based on the parsed data.

Additional context Unfortunately, I do not have control over the message source. Integrating these extensions into the protobuf library itself would allow handling of non-standard JSON formats.

honglooker commented 3 months ago

cc @jskeet

jskeet commented 3 months ago

I think the callback idea - somewhere in JsonParserSettings feels a little more comfortable to me than having a virtual method.

That said, I'd also say that this is a very non-orthodox scenario - if this really is JSON that's meant to correspond to a protobuf message, it's really odd that it's not using the standard JSON representation. I'm always nervous about features that are born out of "there's something weird going on somewhere that's not under our control, and we're just trying to remediate it".

github-actions[bot] commented 2 days ago

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.