Skip to content

Add useOptionalForGetters option for Java 8 java.util.Optional on getters #344

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

Merged
merged 1 commit into from
Jan 21, 2018

Conversation

holsky
Copy link
Contributor

@holsky holsky commented Apr 30, 2015

This is just a draft - I would like to get some comments from you on the initial direction. Would it work this way or am I on the wrong track?
And is there a good reason why there are no tests for PropertyRule? (If not I'd implement a few happy path tests).
Fixes #342

@holsky
Copy link
Contributor Author

holsky commented May 2, 2015

and well - can you think of a way to implement this without breaking java 7 compatibility? :-)

@joelittlejohn
Copy link
Owner

I think there are ways :) I haven't had a chance to look through this yet,
but I believe there would be ways to achieve this using Code Model without
directly introducing a dependency on Java 8 in the plugin (slightly awkward
but still possible).
On 2 May 2015 20:35, "Holger Schmeisky" [email protected] wrote:

and well - can you think of a way to implement this without breaking java
7 compatibility? :-)


Reply to this email directly or view it on GitHub
#344 (comment)
.

@joelittlejohn
Copy link
Owner

This PR is incomplete and stale. I'm closing this as I don't believe it's going to be completed, but we can use these changes for reference in the future.

@EitZei
Copy link

EitZei commented Sep 15, 2017

@joelittlejohn I would really appreciate this feature and would be willing to work the get it included. What did you feel was missing from the earlier pull request?

@joelittlejohn
Copy link
Owner

@EitZei Do you have some thoughts about how to implement this without breaking Jav 7 compatibility?

@joelittlejohn
Copy link
Owner

Maybe we should cut a 1.0 version of this library for Java 8 and drop Java 7 support going forward. There are a load of things we would do differently in the generated code if we were target Java 8 and later I think. Many modern Java constructs can't be supported by CodeModel though (the library we use to create .java files) so maybe we should also try to move to something else.

I've recently found https://github.com/square/javapoet but I'm also not sure how well this library supports either Java 7 or Java 8 constructs.

@joelittlejohn
Copy link
Owner

@EitZei If you really do need this feature (and soon), you should consider building your own version of jsonschema2pojo that has this PR merged.

@EitZei
Copy link

EitZei commented Sep 16, 2017

To my limited understanding this PR is already Java 7 compatible after the https://github.com/joelittlejohn/jsonschema2pojo/pull/344/files/8b5a566c514d81f7976747db6468904265cd3e96..HEAD amendment which makes the dependency to java.util.Optional to be just a String reference.

@joelittlejohn
Copy link
Owner

Ha, you're right. I actually didn't notice that update to the PR.

@EitZei
Copy link

EitZei commented Sep 18, 2017

Given this information would you be willing to merge this PR?

@joelittlejohn
Copy link
Owner

Yes, I think this can be merged. I might change the config property name here but other than that I think this can be included in the next release.

@joelittlejohn joelittlejohn reopened this Sep 18, 2017
@joelittlejohn
Copy link
Owner

joelittlejohn commented Sep 18, 2017

There's a bit more required here. This currently only supports the older required syntax of specifying a boolean inside the property schema. Before we support this we'll have to also support the newer syntax of specifying an array of property names (that are required properties) in the object schema.

@holsky
Copy link
Contributor Author

holsky commented Oct 3, 2017

Nice to get a visit from the past. I completely forgot how the traversal works, but I would either

  1. access the parent node and get the required fields and check if this one is contained or
  2. pass the required fields down as a parameter maybe in the jclass

which one do you think is better?

check whether property is in the list of required properties
@holsky holsky force-pushed the use-java8-optional branch from fd1d002 to be3d35c Compare October 19, 2017 21:11
@holsky
Copy link
Contributor Author

holsky commented Oct 19, 2017

@joelittlejohn I copied the approach from NotRequiredRule to just loop through the required list.

I did not include this in ScalaGen, is your goal to have feature parity?

@holsky
Copy link
Contributor Author

holsky commented Nov 3, 2017

@joelittlejohn let's not make the same mistake twice :) when do you think you will have a chance to look at it?

@holsky
Copy link
Contributor Author

holsky commented Jan 21, 2018

oh no @joelittlejohn it's happening again :) is there anything I can do to help you merge this?

@joelittlejohn joelittlejohn merged commit 0103c0f into joelittlejohn:master Jan 21, 2018
@joelittlejohn
Copy link
Owner

Let's do this 👍

@EitZei
Copy link

EitZei commented Jan 22, 2018

Awesome work @holsky and @joelittlejohn! Any plans on making a new release?

@joelittlejohn
Copy link
Owner

@EitZei the awesome work is all @holsky 😄

Another major change that has been merged recently is the move away from commons-lang to 'native' Java implementations of toString, equals and hashCode. I think I'll release an alpha/beta soon because I'm slightly concerned that some of the recent changes may have some unexpected consequences.

@joelittlejohn joelittlejohn changed the title add useJava8OptionalForNonRequiredFields option Add useOptionalForGetters option for Java 8 java.util.Optional on getters Feb 1, 2018
@joelittlejohn joelittlejohn added this to the 1.0.0-alpha1 milestone Feb 1, 2018
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.

using Optional for non-required values
3 participants