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

fix: various issues with API structs #102

Merged
merged 1 commit into from
Nov 18, 2024
Merged

Conversation

csatib02
Copy link
Member

@csatib02 csatib02 commented Nov 17, 2024

This PR addresses issue #26. The problem described in the ticket occurs because the omitempty directive in the JSON struct tag instructs the encoding/json library to omit fields with a "zero value." The zero value depends on the field's type; for structs, the zero value is an initialized but empty struct.

Solution:

  • To resolve this issue, all struct fields have been changed to pointers. This ensures that the omitempty directive omits fields that are nil, as the zero value for a pointer is nil.
  • There were a couple of cases where it was possible to cause a nil-pointer panic.
  • Added several test cases to verify that the implementation works as intended.

NOTE: The reason why yaml marshalling worked, is becuase yaml has a different implementation for the omitempty tag. It treats empty collections (like maps and slices) as well as empty but initialized structs as "omittable," even when non-nil..

Signed-off-by: Bence Csati <bence.csati@axoflow.com>
@csatib02 csatib02 added the bug Something isn't working label Nov 17, 2024
@csatib02 csatib02 self-assigned this Nov 17, 2024
@csatib02 csatib02 linked an issue Nov 17, 2024 that may be closed by this pull request
Copy link
Member

@pepov pepov left a comment

Choose a reason for hiding this comment

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

Nice one!

Base automatically changed from feat/batch-processor to main November 18, 2024 08:19
Copy link
Collaborator

@OverOrion OverOrion left a comment

Choose a reason for hiding this comment

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

Nice, thank you very much! 🚀

@csatib02 csatib02 merged commit b8c285f into main Nov 18, 2024
11 checks passed
@csatib02 csatib02 deleted the fix/issues-with-struct branch November 18, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigatite why omitepmty does not seem to work
3 participants