Skip to content

APIv2: Support magic methods on messages in MarshalJSONPB, etc. #1017

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

Closed
au-phiware opened this issue Jan 16, 2020 · 3 comments
Closed

APIv2: Support magic methods on messages in MarshalJSONPB, etc. #1017

au-phiware opened this issue Jan 16, 2020 · 3 comments

Comments

@au-phiware
Copy link

The v1 API's jsonpb package checks for custom MarshalJSONPB and UnmarshalJSONPB methods on the type being operated on, and use it when present.

The v2 API should preserve this behaviour, or at least provide an alternative mechanism to customise the behaviour of the marshaller/unmarshaller with respect to a nominated message type.

@cybrcodr
Copy link
Contributor

The v2 protojson API is meant to follow the Protobuf JSON spec, and the spec does not allow for custom serialization.

Adding the JSONPBMarshaler and JSONPBUnmarshaler at the time #325 was a way to support dynamic messages in JSON serialization.

v2 serialization supports dynamic messages that implement the protoreflect API. It does not allow for custom JSON output/input as it still needs to make sure it abides by the spec.

@dsnet
Copy link
Member

dsnet commented Jan 16, 2020

The magic methods existed to support message implementations other than generated messages. In v2, this becomes unnecessary as all messages are required to implement protobuf reflection moving forward.

alternative mechanism to customise the behaviour of the marshaller/unmarshaller with respect to a nominated message type.

The v1 documentation explicitly says that implementations must properly follow the protobuf JSON specification. These methods were never intended for custom behavior.

@au-phiware
Copy link
Author

I see, thanks for the clarification.

@golang golang locked and limited conversation to collaborators Jul 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants