-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
support custom message validation in JSONPB when checking for required fields #509
Comments
Adding I know I have been saying #364 is the solution for many problems, and I truly believe it is. I'm still working on the API design, and it's really tricky to get the details right with all the edge cases of the protobuf specification. The being said, modifying the logic of |
I agree. And a behaviorally complete message interface would be awesome! I suppose an alternate resolution might be to just have I think that would effectively make this check a no-op when marshaling and unmarshaling my dynamic message implementation. (My implementation already does this check internally anyway.) |
A fix of this nature sounds fine. Want to send a PR taking that approach? |
Sure |
Pull request #472 added new checks to ensure that messages are valid -- e.g. any field that is required is actually present.
I'm filing this issue primarily to support dynamic message implementations (such as this, which works fine in
master
, but does not work indev
).Attempts to use
jsonpb
to marshal/unmarshal a dynamic message can now result in a panic:This happens if the message struct contains any unexported pointer values that are non-nil (including slice or map fields that contain a non-nil pointer element). When examining a message, it uses
val.Interface().(proto.Message)
to see if the pointer is a nested message which needs to be recursively checked.ValidateRecursive()
method which can be called instead of using the default check.proto
package, such as:I have a fix that addresses the first bullet.
The second bullet would, of course, allow
jsonpb
to share code with theproto
package for checking that required fields are present. But it would also make it easier for messages to implementValidateRecursive()
since they could call this exported function to apply default logic (if applicable), and they could also use it to apply normal validation for nested message fields.The text was updated successfully, but these errors were encountered: