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

Scala case classes support #598

Closed
anthony-cros opened this issue Jul 19, 2016 · 8 comments
Closed

Scala case classes support #598

anthony-cros opened this issue Jul 19, 2016 · 8 comments
Milestone

Comments

@anthony-cros
Copy link

That would be terrific :)

I may be able to contribute actually, given a few pointers!

@joelittlejohn
Copy link
Owner

Hi @anthony-cros, thanks for raising this.

This and #593 (Kotlin support) have been raised recently. I'm not sure it makes sense to target new languages from this tool. Fundamentally, all the code here is about reading a JSON schema rule and creating a some Java for it (Java annotations, Java naming and structural conventions, identifiers that meet Java's restrictions, etc). If you target a new language, you're effectively rewriting everything.

Scala and Kotlin could both be considered alternative dialects with which to produce the same Java type, but the burden on this project would be huge, particularly as all new features would have to be supported in Java, Scala and Kotlin. I don't think any individual contributor would have a chance achieving this well.

So, given that it's really easy to navigate through a JSON object (in this case the schema) I think it would be better to create your own tool that does this and does whatever is required to generate Scala output.

@joelittlejohn joelittlejohn changed the title scala case classes support Scala case classes support Jul 25, 2016
@jmfayard
Copy link

Thanks for the comment. Makes sense.

@anthony-cros
Copy link
Author

anthony-cros commented Jul 25, 2016

Actually, I've been piping the output to scalagen to achieve that... It's still less code than doing it myself from the ground up. I understand what you mean about supporting two "different" languages, so maybe as some sort of plug-ins?

EDIT: see how javatoscala uses scalagen to do that conversion

@joelittlejohn
Copy link
Owner

@anthony-cros If we could achieve this by allowing a post-processor to be configured for the Java output then this might be okay. As long as it's a purely mechanical process and doesn't require customization or modification every time we add a new feature.

@joelittlejohn joelittlejohn reopened this Aug 14, 2017
@joelittlejohn
Copy link
Owner

I've been experimenting with this one and I've had some success (thanks @anthony-cros!). I think I can enable this feature soon. I expect with some careful adjustment of config properties, people will be able to get useful Scala.

@joelittlejohn joelittlejohn added this to the 0.5.0 milestone Sep 10, 2017
@joelittlejohn
Copy link
Owner

I've implemented something. If someone could install the latest 0.5.0-SNAPSHOT locally and try this it would be much appreciated. With the maven plugin simply add:

<targetLanguage>scala</targetLanguage>

to your configuration.

Of course, tweak your other config options accordingly to change the Scala output.

@joelittlejohn
Copy link
Owner

I'm having some problems with the scalagen dependency due to the way it defines artifact names via profile activation. I'll reopen this until I have this sorted.

wigbam pushed a commit to wigbam/jsonschema2pojo that referenced this issue Nov 25, 2017
@AceHack
Copy link

AceHack commented Jun 10, 2020

Are there some examples of using this for scala around?

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

No branches or pull requests

4 participants