Skip to content

Commit 560bdb6

Browse files
authored
jsonpb: strictly document JSONPBMarshaler and JSONPBUnmarshaler behavior (#662)
Strictly document that custom JSONPBMarshaler and JSONPBUnmarshaler must properly follow the JSON to proto specification: https://developers.google.com/protocol-buffers/docs/proto3#json These interfaces are currently necessary since there is no high-level API for proto reflection. However, as we prepare to move to a world where there is first-class support for proto reflection, these interfaces should be deprecated. When we eventually have proto reflection, and implement jsonpb entirely in terms of reflection, then it should not matter whether we called these custom marshalers or not since they should both implement the same specification. Note that this documentation is already implied by the fact that this whole package implements the proto-JSON specification and in order for it to do so, it implies that any custom interfaces it calls also follows the specification. We strictly document this to dissuade improper implementations.
1 parent 11bd559 commit 560bdb6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

jsonpb/jsonpb.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ func defaultResolveAny(typeUrl string) (proto.Message, error) {
106106
// way they are marshaled to JSON. Messages that implement this should
107107
// also implement JSONPBUnmarshaler so that the custom format can be
108108
// parsed.
109+
//
110+
// The JSON marshaling must follow the proto to JSON specification:
111+
// https://developers.google.com/protocol-buffers/docs/proto3#json
109112
type JSONPBMarshaler interface {
110113
MarshalJSONPB(*Marshaler) ([]byte, error)
111114
}
@@ -114,6 +117,9 @@ type JSONPBMarshaler interface {
114117
// the way they are unmarshaled from JSON. Messages that implement this
115118
// should also implement JSONPBMarshaler so that the custom format can be
116119
// produced.
120+
//
121+
// The JSON unmarshaling must follow the JSON to proto specification:
122+
// https://developers.google.com/protocol-buffers/docs/proto3#json
117123
type JSONPBUnmarshaler interface {
118124
UnmarshalJSONPB(*Unmarshaler, []byte) error
119125
}

0 commit comments

Comments
 (0)