Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bigtable): Add MarshalJSON to allow clients to get a stringified version of the protobuf #10679

Merged
merged 22 commits into from
Aug 22, 2024

Conversation

ron-gal
Copy link
Contributor

@ron-gal ron-gal commented Aug 13, 2024

No description provided.

@ron-gal ron-gal requested review from a team as code owners August 13, 2024 17:02
@product-auto-label product-auto-label bot added the api: bigtable Issues related to the Bigtable API. label Aug 13, 2024
bigtable/type.go Outdated Show resolved Hide resolved
bigtable/type.go Outdated Show resolved Hide resolved
@ron-gal ron-gal changed the title feat(bigtable): Add ToJson to allow clients to get a stringified version of the protobuf feat(bigtable): Add MarshalJSON to allow clients to get a stringified version of the protobuf Aug 13, 2024
bigtable/type.go Outdated Show resolved Hide resolved
if !proto.Equal(got, want) {
t.Errorf("got type %v, want: %v", got, want)
wantJSON := "{\"stringType\":{\"encoding\":{\"utf8Raw\":{}}}}"
if strings.ReplaceAll(string(gotJSON), " ", "") != wantJSON {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than testing that the json equals a known string, I think we can instead just test that round tripping the object from json and back yield the "correct" thing? Comparing json strings has the potential for false errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

bigtable/type.go Outdated

// Type wraps the protobuf representation of a type. See the protobuf definition
// for more details on types.
type Type interface {
proto() *btapb.Type
}

var marshalOptions = protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
var unmarshalOptions = protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we want DiscardUnknown? assuming that does what it sounds like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

bigtable/type_test.go Outdated Show resolved Hide resolved
@steveniemitz steveniemitz merged commit 663f399 into googleapis:main Aug 22, 2024
8 of 10 checks passed
@ron-gal ron-gal deleted the add_to_json branch August 22, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the Bigtable API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants