-
-
Notifications
You must be signed in to change notification settings - Fork 184
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: add un/marshal JSON preset for Java #596
feat: add un/marshal JSON preset for Java #596
Conversation
hi @jonaslagoni, Kindly look into my PR and let me know if I am heading in the right direction or not. 🙂 |
@jonaslagoni I am currently facing errors while writing a test for un/marshalling in Java and not able to figure out what the error kindly look into them |
test/generators/java/presets/__snapshots__/CommonPreset.spec.ts.snap
Outdated
Show resolved
Hide resolved
test/generators/java/presets/__snapshots__/CommonPreset.spec.ts.snap
Outdated
Show resolved
Hide resolved
Definitely in the right direction 👍 Just keep iterating 🙂 |
@jonaslagoni I have implemented the changes you have mentioned. Kindly look at them and let me know if any more changes are required. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a couple of remarks 🙂
Remember your code smells from sonarcloud 🙂
Pull Request Test Coverage Report for Build 1835217589
💛 - Coveralls |
@jonaslagoni everything is working now 😊. I ran |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small changes requested, looking good! 💪
We need to enlighten the user of the new preset, so they can start using it!
We need to adapt our Java language documentation: https://github.com/asyncapi/modelina/blob/master/docs/languages/Java.md
Here you could add something along the lines of:
## Include JSON marshaling and unmarshaling methods
Sometimes you just want to convert your class to JSON without the use of annotations such as Jackson.
Check out this [example for a live demonstration](https://github.com/asyncapi/modelina/blob/master/examples/java-generate-marshal).
External dependencies
- Requires [org.json package](https://search.maven.org/artifact/org.json/json/20211205/bundle) to work
Next, we need to create an example to show exactly how a user can enable this option (as well as always ensuring it works). We do that by adding the following example: https://github.com/asyncapi/modelina/blob/master/examples/java-generate-marshal
You can copy this template for a good start: https://github.com/asyncapi/modelina/tree/master/examples/TEMPLATE
Read more about adding examples here: https://github.com/asyncapi/modelina/blob/master/docs/contributing.md#adding-examples
Let me know if you have any questions!
// eslint-disable-next-line | ||
const getType = `jsonObject.get${properties[prop].type?.toString().charAt(0).toUpperCase()}${properties[prop].type?.toString().slice(1)}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming these lines are the problems to eslint complaining?
// eslint-disable-next-line | |
const getType = `jsonObject.get${properties[prop].type?.toString().charAt(0).toUpperCase()}${properties[prop].type?.toString().slice(1)}`; | |
const getType = `jsonObject.get${FormatHelpers.upperFirst(properties[prop].type?.toString())}` |
Was it the optional chaining of properties[prop].type?
, or the access of properties[prop]
?
You could try the following:
const propModel = properties[String(prop)];
if(propModel.type === 'undefined') {
Logger.error(`Could not render unmarshal for property ${prop}`);
return;
}
hi @jonaslagoni , I have made changes but I am facing an error kindly look at them. |
That is indeed weird. Have you tried printing the content or debugging the test to see what is actually inside Is it just some hidden character not matching or? |
@jonaslagoni This error is actually occurring because I changed the code from
to
But if I remove the following imports the code works fine I think it is not able to process multiple imports.
|
It definitely should be 😄 Do you mind trying to print out what is inside the array |
Here we are testing two dependencies:
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comments, nearly there, looking great 💪
@jonaslagoni Added example for marshalling. Kindly review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, awesome @ritik307 🎉
/rtm |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@all-contributors please add @ritik307 for code, test, example |
🎉 This PR is included in version 0.48.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I've put up a pull request to add @ritik307! 🎉 |
🎉 This PR is included in version 1.0.0-next.23 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
src/generators/java/presets/CommonPreset.ts
Related issue(s)
Fixed #488