jsonpb package - github.com/golang/protobuf/jsonpb - Go Packages (original) (raw)

Package jsonpb provides functionality to marshal and unmarshal between a protocol buffer message and JSON. It follows the specification athttps://developers.google.com/protocol-buffers/docs/proto3#json.

Do not rely on the default behavior of the standard encoding/json package when called on generated message types as it does not operate correctly.

Deprecated: Use the "google.golang.org/protobuf/encoding/protojson" package instead.

This section is empty.

This section is empty.

Unmarshal unmarshals a JSON object from r into m.

UnmarshalNext unmarshals the next JSON object from d into m.

UnmarshalString unmarshals a JSON object from s into m.

AnyResolver takes a type URL, present in an Any message, and resolves it into an instance of the associated message.

type JSONPBMarshaler interface { MarshalJSONPB(*Marshaler) ([]byte, error) }

JSONPBMarshaler is implemented by protobuf messages that customize the way they are marshaled to JSON. Messages that implement this should also implement JSONPBUnmarshaler so that the custom format can be parsed.

The JSON marshaling must follow the proto to JSON specification:

https://developers.google.com/protocol-buffers/docs/proto3#json

Deprecated: Custom types should implement protobuf reflection instead.

type JSONPBUnmarshaler interface { UnmarshalJSONPB(*Unmarshaler, []byte) error }

JSONPBUnmarshaler is implemented by protobuf messages that customize the way they are unmarshaled from JSON. Messages that implement this should also implement JSONPBMarshaler so that the custom format can be produced.

The JSON unmarshaling must follow the JSON to proto specification:

https://developers.google.com/protocol-buffers/docs/proto3#json

Deprecated: Custom types should implement protobuf reflection instead.

type Marshaler struct {

OrigName [bool](/builtin#bool)


EnumsAsInts [bool](/builtin#bool)


EmitDefaults [bool](/builtin#bool)


Indent [string](/builtin#string)


AnyResolver [AnyResolver](#AnyResolver)

}

Marshaler is a configurable object for marshaling protocol buffer messages to the specified JSON representation.

Marshal serializes a protobuf message as JSON into w.

MarshalToString serializes a protobuf message as JSON in string form.

type Unmarshaler struct {

AllowUnknownFields [bool](/builtin#bool)


AnyResolver [AnyResolver](#AnyResolver)

}

Unmarshaler is a configurable object for converting from a JSON representation to a protocol buffer object.

Unmarshal unmarshals a JSON object from r into m.

UnmarshalNext unmarshals the next JSON object from d into m.