func MessageToJSON(msg protoutil.Message) (jsonb.JSON, error) {
	// Convert to json.
	jsonEncoder := jsonpb.Marshaler{}
	msgJSON, err := jsonEncoder.MarshalToString(msg)
	if err != nil {
		return nil, errors.Wrapf(err, "marshaling %s; msg=%+v", proto.MessageName(msg), msg)
	}

	// We need to take encoded json object and, unfortunately, unmarshal
	// it again, this time as a string->value map, so that we can construct
	// JSONB object to return.
	var msgMap map[string]interface{}
	if err := json.Unmarshal([]byte(msgJSON), &msgMap); err != nil {
		return nil, errors.Wrap(err, "unmarshaling to map")
	}

	// Build JSONB.
	builder := jsonb.NewObjectBuilder(len(msgMap))
	for k, v := range msgMap {
		jv, err := jsonb.MakeJSON(v)
		if err != nil {
			return nil, errors.Wrapf(err, "encoding json value for %s", k)
		}
		builder.Add(k, jv)
	}
	return builder.Build(), nil
}
// MessageToJSON converts a protocol message into a JSONB object.
MessageToJSON converts a protocol message into a JSONB object.
// MessageToJSON converts a protocol message into a JSONB object .
func MessageToJSON(msg protoutil.Message) (jsonb.JSON, error) {
	jsonEncoder := jsonpb.Marshaler{}
	msgJSON, err := jsonEncoder.MarshalToString(msg)
	if err != nil {
		return nil, errors.Wrapf(err, "marshaling %s; msg=%+v", proto.MessageName(msg), msg)
	}
	var msgMap map[string]interface{}
	if err := json.Unmarshal([]byte(msgJSON), &msgMap); err != nil {
		return nil, errors.Wrap(err, "unmarshaling to map")
	}
	builder := jsonb.NewObjectBuilder(len(msgMap))
	for k, v := range msgMap {
		jv, err := jsonb.MakeJSON(v)
		if err != nil {
			return nil, errors.Wrapf(err, "encoding json value for %s", k)
		}
		builder.Add(k, jv)
	}
	return builder.Build(), nil
}
func MessageToJSON ( msg protoutil . Message ) ( jsonb . JSON , error ) { jsonEncoder := jsonpb . Marshaler { } msgJSON , err := jsonEncoder . MarshalToString ( msg ) if err != nil { return nil , errors . Wrapf ( err , " " , proto . MessageName ( msg ) , msg ) } var msgMap map [ string ] interface { } if err := json . Unmarshal ( [ ] byte ( msgJSON ) , & msgMap ) ; err != nil { return nil , errors . Wrap ( err , " " ) } builder := jsonb . NewObjectBuilder ( len ( msgMap ) ) for k , v := range msgMap { jv , err := jsonb . MakeJSON ( v ) if err != nil { return nil , errors . Wrapf ( err , " " , k ) } builder . Add ( k , jv ) } return builder . Build ( ) , nil }
MessageToJSON converts a protocol message into a JSONB object.
MessageToJSON converts a protocol message into a JSONB object .
// Convert to json. // We need to take encoded json object and, unfortunately, unmarshal // it again, this time as a string->value map, so that we can construct // JSONB object to return. // Build JSONB.