Open bsagal opened 3 months ago
cc @jskeet
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".
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.
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
Unseal
JsonParser
and MakeTryParseSingleValue
protected virtual
: This modification would allow subclassing ofJsonParser
to overrideTryParseSingleValue
, enabling custom handling of hex-encoded byte fields while maintaining default behavior when necessary.Optional Callback for
TryParseSingleValue
: Introducing an optional callback mechanism withinTryParseSingleValue
would offer flexibility to override default parsing behavior for specific fields, accommodating diverse JSON formats.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.