Add support of ignore tag for json.marshal

This commit is contained in:
VladPavliuk
2024-07-13 14:13:59 +03:00
parent d845a07519
commit 64ae99f016
2 changed files with 24 additions and 1 deletions
@@ -368,4 +368,25 @@ utf8_string_of_multibyte_characters :: proc(t: ^testing.T) {
val, err := json.parse_string(`"🐛✅"`)
defer json.destroy_value(val)
testing.expectf(t, err == nil, "Expected `json.parse` to return nil, got %v", err)
}
@test
struct_with_ignore_tags :: proc(t: ^testing.T) {
My_Struct :: struct {
a: string `json:"_,ignore"`,
}
my_struct := My_Struct{
a = "test",
}
my_struct_marshaled, marshal_err := json.marshal(my_struct)
defer delete(my_struct_marshaled)
testing.expectf(t, marshal_err == nil, "Expected `json.marshal` to return nil error, got %v", marshal_err)
my_struct_json := transmute(string)my_struct_marshaled
expected_json := `{}`
testing.expectf(t, expected_json == my_struct_json, "Expected `json.marshal` to return %s, got %s", expected_json, my_struct_json)
}