-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Issue with json struct tag omitempty #20
Comments
I investigated a little bit more, and found that I could change this code (https://github.com/shigetaichi/xsv/blob/main/types.go#L220) from: if omitEmpty && value == "" {
return nil
} to: if omitEmpty && value == "" {
field.Set(reflect.New(field.Type().Elem()))
return nil
} and it seems to work, not sure if it breaks something... |
I made a fork with a small fix that seems to work. The tests passes at least. But, I'm actually not sure if it breaks something... |
@PatrLind I am getting an error with a pointer type of primitive type with omitempty attached. To verbalize the process that line 220 is doing, If the field is "structure pointer type and omitempty", then the change description you gave us will assign the specified type to the field argument, which will allow us to execute the decode.go line 171 process correctly. On the other hand, if the field is a "primitive pointer type and omitempty", the process is still not followed properly😅. |
gocarina/gocsv#135
|
… an embedded pointer type structure #20
@PatrLind At that point, it would determine if the tag had This 👆 part was the factor of this issue. Since the existing code only checked for I have created a PR and plz check here. -> #21 |
Your changes in the PR seems to fix the issue, thank you! |
I found this bug in gocsv: gocarina/gocsv#263
and thought I would test the same on your project, since it seems better in many ways.
But unfortunately it seems that this project has the same bug, or at least what I think is a bug.
The error is that the code panics when having json struct tags with omitempty on them. I haven't investigated very deeply, but it seems like it should not panic.
Example panic output:
Test code I used:
The text was updated successfully, but these errors were encountered: