Debian Codegraph @

vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go

raw
1 package runtime
2
3 import (
4 "encoding/json"
5 "io"
6 )
7
8 // JSONBuiltin is a Marshaler which marshals/unmarshals into/from JSON
9 // with the standard "encoding/json" package of Golang.
10 // Although it is generally faster for simple proto messages than JSONPb,
11 // it does not support advanced features of protobuf, e.g. map, oneof, ....
12 type JSONBuiltin struct{}
13
14 // ContentType always Returns "application/json".
15 func (*JSONBuiltin) ContentType() string {
16 return "application/json"
17 }
18
19 // Marshal marshals "v" into JSON
20 func (j *JSONBuiltin) Marshal(v interface{}) ([]byte, error) {
21 return json.Marshal(v)
22 }
23
24 // Unmarshal unmarshals JSON data into "v".
25 func (j *JSONBuiltin) Unmarshal(data []byte, v interface{}) error {
26 return json.Unmarshal(data, v)
27 }
28
29 // NewDecoder returns a Decoder which reads JSON stream from "r".
30 func (j *JSONBuiltin) NewDecoder(r io.Reader) Decoder {
31 return json.NewDecoder(r)
32 }
33
34 // NewEncoder returns an Encoder which writes JSON stream into "w".
35 func (j *JSONBuiltin) NewEncoder(w io.Writer) Encoder {
36 return json.NewEncoder(w)
37 }