Open lesovsky opened 2 years ago
That seems reasonable, but I don't think it is possible. The MarshalJSON()
method defined on the pgtype doesn't have access to the struct tags. And a quick look at the json package docs seems to indicate that omitempty
has a hard-coded list of zero values.
I have struct with optional field. This optional field is not used sometimes and in such cases marshalling fails with error. Is it possible to omit such fields transparently?
omitempty
tag not working and test returns:I would like that could working like with native types:
which returns normally with no error and prints
{"name":"vasya"}
with ommited optional field.