Skip to content

bool set to false is skipped during marshal #109

@jadn123

Description

@jadn123

If you have a bool field in the proto.Message and this is set to false it will not be part of the output map[string]bigquery.Value during marshalling. This means that when inserting the data into BigQuery this column will get the value null.

I think null would be fine if the type was the wrapper BoolValue but for bool it should resolve to false in the end.

I modified the existing test in example_test.go

func TestMarshal(t *testing.T) {
	msg := &library.Book{
		Name:   "publishers/123/books/456",
		Author: "P.L. Travers",
		Title:  "Mary Poppins",
		Read:   false,
	}
	row, err := protobq.Marshal(msg)

	if err != nil {
		// TODO: Handle error.
	}
	expected := map[string]bigquery.Value{
		"name":   "publishers/123/books/456",
		"author": "P.L. Travers",
		"title":  "Mary Poppins",
		"read":   false,
	}

	fmt.Println("Expected:", expected)
	fmt.Println("Got:", row)
	fmt.Println("Equal:", cmp.Equal(expected, row))
}

Output

Expected: map[author:P.L. Travers name:publishers/123/books/456 read:false title:Mary Poppins]
Got: map[author:P.L. Travers name:publishers/123/books/456 title:Mary Poppins]
Equal: false

I can't find any MarshalOptions to control this behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions