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

Separate javaType into 'existingJavaType' and 'javaType' #828

Closed
joelittlejohn opened this issue Jan 31, 2018 · 10 comments
Closed

Separate javaType into 'existingJavaType' and 'javaType' #828

joelittlejohn opened this issue Jan 31, 2018 · 10 comments
Labels
Milestone

Comments

@joelittlejohn
Copy link
Owner

At present javaType has two jobs, it can be used to reference an existing classpath type and also to give a newly generated type a fixed fully-qualified name. This was a bad design, for instance:

  1. All 'existing' referenced classes need to be present on the classpath to avoid getting a new class generated, even though in fact there is no need to require them at generation time.
  2. Sources are not regenerated if previous class files are not cleaned from the project, because it's assumed that these types are 'existing' classes that are being used and should not be generated.

We should split these features, so that the schema author needs to be explicit.

@joelittlejohn joelittlejohn modified the milestones: 1.0.0, 1.0.0-alpha2 Jan 31, 2018
@tviegut
Copy link

tviegut commented Mar 13, 2018

First off, great plugin. If this particular item has not been implemented yet, might it be possible to name it "existingJavaType"?

We use UML modeling toolsets that aid in auto-generating API JSON specifications which in turn we then leverage jsonSchema2Pojo durings builds. We've experienced with other jsonSchema2Pojo extensions that deviate a bit from the "norm" that the extension can be improperly named to what seems intuitive which doesn't get picked up in our build process.

One example is the existing feature for "extendsJavaClass" extension that the plugin supports. It never fails that periodically it will get declared as "extendsJavaType" (which does seem to make logical sense as an extension of "javaType") but the resulting POJOs don't pick it up and it takes another cycle to fix. Maybe a wish here...but if the plugin supported both "extendsJavaClass" for backwards compatibility as well as "extendsJavaType" perhaps it would eliminate this for anyone who's perhaps has also encountered it.

In any event, just throwing out thoughts from day-to-day experience.

@joelittlejohn joelittlejohn changed the title Separate javaType into 'existingType' and 'javaType' Separate javaType into 'existingJavaType' and 'javaType' Mar 13, 2018
@tviegut
Copy link

tviegut commented Mar 14, 2018

Thanks!!

@joelittlejohn
Copy link
Owner Author

Benefits I think we'll get after implementing this:

  1. People can use existingJavaType to reference a class even if that class is not on the classpath

  2. People can re-run their build without having to 'clean', because the generated output will not depend on the current state of the classpath

@tviegut
Copy link

tviegut commented Mar 14, 2018

Yes, this is a big plus for us. We've observed the limitation that you're calling out in resolving our own existing classes within our gradle builds. So needless to say, when we caught that this was going to be in this next release we were pleased.

@pnmalav
Copy link

pnmalav commented Jun 10, 2018

It seems the feature of "existingJavaType" already works if we specify only "javaType" and no "type".

{
  "type":"object",
  "properties": {
    "baz": {
      "javaType": "my.Custom"
    }
  }
}

@joelittlejohn
Copy link
Owner Author

@pnmalav yes, that's right. javaType currently allows you to either create new classes or reference existing classes from the classpath.

In the next release, you will use javaType to give a specific name to a new class. If you want to refer to an existing class, you will use existingJavaType.

@pnmalav
Copy link

pnmalav commented Jun 10, 2018

@joelittlejohn the example I provided works even if my.Custom is not in classpath. There is no Custom class created, unless I specify "type":"object".

This will create a Custom class as well

{
  "type":"object",
  "properties": {
    "baz": {
      "javaType": "my.Custom",
      "type": "object"
    }
  }
}

@joelittlejohn
Copy link
Owner Author

@pnmalav thanks, I wasn't aware of this workaround. I think this is the kind of ambiguous behaviour that we need to fix.

@ajayboseac
Copy link

ajayboseac commented May 6, 2019

Thanks for this Plugin!

@joelittlejohn in which version of:jsonschema2pojo-maven-plugin has this issue been fixed?

@joelittlejohn
Copy link
Owner Author

@ajayboseac This change was introduced in 1.0.0-alpha3. Check the CHANGELOG.md (and the 'Milestone' field on this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants