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

Use Sealed Trait As Base Class? #501

Open
dalegaspi opened this issue Mar 12, 2019 · 3 comments · May be fixed by #521
Open

Use Sealed Trait As Base Class? #501

dalegaspi opened this issue Mar 12, 2019 · 3 comments · May be fixed by #521

Comments

@dalegaspi
Copy link

I'm trying to use jsoniter-scala with the case classes generated using this awesome tool. the hindrance that i see is that for cases like this a trait is generated, but the problem is i cannot use jsoniter-scala macros to generate decoders because the base trait is not sealed. can we have perhaps an option to make the generated base class sealed for this purpose?

@plokhotnyuk
Copy link

@dalegaspi You can try to add the sealed keyword before trait here, build the tool and publish locally to check if it works for your case.

@dalegaspi
Copy link
Author

@plokhotnyuk yes i saw that...i was going to make the change but then i realized why this was not the default behavior: in a case where the parent class is in a different .xsd file as the child class (which applies in my case), this poses a problem since a sealed trait and its implementation needs to be in the same .scala file...there's a caveat of making sure to create an "intermediate class" that can be inherited in another xsd file. good thing there is code in there to indicate if the trait is not a root and ensure that it doesn't apply sealed keyword.

right now i'm doing it the lazy way and do a search and replace (to add sealed) in the generated .scala source files... if i don't run to other issues then i will pursue further.

@dalegaspi
Copy link
Author

update: looks like manually adding the appropriate sealed to the root traits did the trick! 😊😊😊 ...the generated classes now work with jsoniter-scala macros!!

now i'm just going to make changes to the plugin and make a PR to have an option to make the root traits sealed.

cc: @plokhotnyuk

@Fokko Fokko linked a pull request Nov 10, 2019 that will close this issue
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 a pull request may close this issue.

2 participants