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

Safe json.RawMessage and json.Number #233

Merged
merged 9 commits into from Apr 10, 2023

Conversation

mgilbir
Copy link
Contributor

@mgilbir mgilbir commented Apr 4, 2023

There are two types in encoding/json that are special:

  • json.RawMessage is defined as a []byte and it is used to store unparsed JSON. When encountered in a struct, gofakeit generates a random array of bytes but that doesn't mean that it is a valid JSON, and it will fail when trying to json.Marshal the struct.
  • json.Number is defined as a string and it is used to represent numeric types in JSON. When encountered in a struct, gofakeit generates a random string that cannot be represented as a number and it will fail when trying to json.Marshal the struct.

This PR adds support for those two types in the encoding/json package ensuring that valid JSON values are generated by gofakeit by default and that the resulting struct can be marshalled to JSON. More precise output control is still available via struct tags.

There are two commits that add stability and ensure reusing the Faker object in CSV, JSON, and XML. If you prefer that those two commits are moved to their own PR, I'm happy to extract them.

Other than that improvement to existing functionality, all the existing tests pass and no behaviour changes are introduced to already released functionality.

@brianvoe
Copy link
Owner

brianvoe commented Apr 6, 2023

I think this looks good. Nice job! If you are ready ill merge it in.

I do want to play around with them a little before i do a release just to get a feel for things. But should be able to get it out soon.

@mgilbir
Copy link
Contributor Author

mgilbir commented Apr 7, 2023 via email

@brianvoe brianvoe merged commit 57b7fad into brianvoe:develop Apr 10, 2023
12 checks passed
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.

None yet

2 participants