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

Handle the case if json tag was not overwritten #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

borosr
Copy link

@borosr borosr commented Jan 29, 2023

If the json tag was not present in the go_struct_tags option, the lib would use the default json tag, generated by protobuf.
#22

@borosr borosr self-assigned this Jan 29, 2023
Copy link
Member

@PumpkinSeed PumpkinSeed left a comment

Choose a reason for hiding this comment

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

Actually what you should do, you have to get the o.goStructTags, and if there is a tag from the override than 1. override the value if it exists in the o.goStructTags, 2. add it if it's not exists. The current solution somehow overcomplicate the problme. Correct me if I'm wrong and you are doing this.

@borosr
Copy link
Author

borosr commented Feb 19, 2023

Basically, my implementation is doing the same in the getAdditionalTags function, where the logic is:

  1. Reading the goStructTags attached to the field - if empty, return with the default json tag
  2. Parsing the passed goStructTags, but skipping those which are generated for gRPC
    At this point, we have an array full of non-existing and/or the overwritten json tag in it
  3. Checking if the parsed array is containing json tag, if not, then add the default json tag to the parsed array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants