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

feat: Adding JSON to Java transformation feature #345

Merged
merged 5 commits into from
Dec 30, 2022

Conversation

Pooja444
Copy link
Contributor

@Pooja444 Pooja444 commented Dec 29, 2022

Github issue

#335

PR explanation

@ritz078 I am adding a JSON to Java transformation feature. I couldn't find any npm libraries that already do this so I used JSON to Kotlin transformation and applied rules to output Java class models.

I applied the below rules -

  • Convert data class <className>( to public class <className> {
  • For every variable val <variableName>: <variableType>, convert it to private <variableType> <variableName>;
  • Add constructor, getters and setters for every variable, as is done in standard Java models
  • If there's a kotlin typealias (created when the entire JSON object is an array), wrap the object in a class. E.g. for typealias Root = List<Root2> it will create a class root with just one list property and its getters, setters
  • Append the constructor, getters setters and close the class when a ')' is found, i.e. kotlin data class end has been reached

I tested this locally with a variety of JSON samples and its working perfectly. Some of the samples I tried were from this StackOverflow answer, in case anyone would like to test this locally

Please review and let me know if any changes are required.

@vercel
Copy link

vercel bot commented Dec 29, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
transform ✅ Ready (Inspect) Visit Preview Dec 29, 2022 at 11:25AM (UTC)

@Pooja444
Copy link
Contributor Author

@ritz078 also I would like to mention that I have added getters, setters but haven't added a constructor to every class. I can do that too if you would like, please let me know

@ritz078
Copy link
Owner

ritz078 commented Dec 29, 2022

I can do that too if you would like, please let me know

You should add it too other users will see it as a bug.

@Pooja444
Copy link
Contributor Author

Pooja444 commented Dec 29, 2022

@ritz078 added the constructor generation logic

@Pooja444
Copy link
Contributor Author

@ritz078 I tested for a number of samples, did all fixes and added constructor generation logic. Can you please review and let me know if it looks good? Thank you!

Copy link
Owner

@ritz078 ritz078 left a comment

Choose a reason for hiding this comment

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

Great job.
Thank you for your contribution 🎉

@ritz078
Copy link
Owner

ritz078 commented Dec 30, 2022

@all-contributors please add @Pooja444 for code contribution

@allcontributors
Copy link
Contributor

@ritz078

I've put up a pull request to add @Pooja444! 🎉

@ritz078 ritz078 merged commit f00c3a0 into ritz078:master Dec 30, 2022
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