e071084ebe
govulncheck / govulncheck (push) Waiting to run
Harness (E2E) / Harnesses (mock LLM) (push) Waiting to run
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Run Tests / Unit Tests (push) Waiting to run
Run Tests / Etcd Integration Tests (push) Waiting to run
33 lines
626 B
Go
33 lines
626 B
Go
package json
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
var protojsonMarshaler = protojson.MarshalOptions{
|
|
EmitUnpopulated: false,
|
|
}
|
|
|
|
type Marshaler struct{}
|
|
|
|
func (j Marshaler) Marshal(v interface{}) ([]byte, error) {
|
|
if pb, ok := v.(proto.Message); ok {
|
|
return protojsonMarshaler.Marshal(pb)
|
|
}
|
|
return json.Marshal(v)
|
|
}
|
|
|
|
func (j Marshaler) Unmarshal(d []byte, v interface{}) error {
|
|
if pb, ok := v.(proto.Message); ok {
|
|
return protojson.Unmarshal(d, pb)
|
|
}
|
|
return json.Unmarshal(d, v)
|
|
}
|
|
|
|
func (j Marshaler) String() string {
|
|
return "json"
|
|
}
|