Skip to content

Commit

Permalink
fix bool unmarshal issue. (istio#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morven Cao authored and istio-testing committed Oct 22, 2019
1 parent da14851 commit a6d3a87
Show file tree
Hide file tree
Showing 6 changed files with 437 additions and 369 deletions.
28 changes: 28 additions & 0 deletions pkg/apis/istio/v1alpha2/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ package v1alpha2
// TODO: create remaining enum types.

import (
"encoding/json"

"github.com/gogo/protobuf/jsonpb"
protobuf "github.com/gogo/protobuf/types"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -54,3 +57,28 @@ type IstioControlPlaneList struct {
v1.ListMeta `json:"metadata,omitempty"`
Items []IstioControlPlane `json:"items"`
}

// define new type from protobuf.BoolValue to marshal/unmarshal jsonpb
type BoolValueForPB struct {
protobuf.BoolValue
}

// MarshalJSON implements the json.JSONMarshaler interface.
func (boolvaluepb *BoolValueForPB) MarshalJSON() ([]byte, error) {
return json.Marshal(boolvaluepb.GetValue())
}

// UnmarshalJSON implements the json.JSONUnmarshaler interface.
func (boolvaluepb *BoolValueForPB) UnmarshalJSON(value []byte) error {
return json.Unmarshal(value, &(boolvaluepb.Value))
}

// MarshalJSONPB implements the jsonpb.JSONPBMarshaler interface.
func (boolvaluepb *BoolValueForPB) MarshalJSONPB(_ *jsonpb.Marshaler) ([]byte, error) {
return boolvaluepb.MarshalJSON()
}

// UnmarshalJSONPB implements the jsonpb.JSONPBUnmarshaler interface.
func (boolvaluepb *BoolValueForPB) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, value []byte) error {
return boolvaluepb.UnmarshalJSON(value)
}
Loading

0 comments on commit a6d3a87

Please sign in to comment.