Files
threshold/internal/daemon/controller/handlers/marshaler.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
775 B
Go
Raw Normal View History

2021-04-29 14:47:13 -07:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
2023-02-02 17:15:17 -08:00
2021-04-29 14:47:13 -07:00
package handlers
import (
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/protobuf/encoding/protojson"
)
2021-05-14 16:26:02 -04:00
// JSONMarshaler provides marshaler used for marshaling all proto as JSON
2021-04-29 14:47:13 -07:00
// in a format expected by the user facing controller API.
func JSONMarshaler() *runtime.JSONPb {
return &runtime.JSONPb{
MarshalOptions: protojson.MarshalOptions{
// Ensures the json marshaler uses the snake casing as defined in the proto field names.
UseProtoNames: true,
// Do not add fields set to zero value to json.
EmitUnpopulated: false,
},
UnmarshalOptions: protojson.UnmarshalOptions{
// Allows requests to contain unknown fields.
DiscardUnknown: true,
},
}
}