-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add 'javaOptional' extension rule to allow individual fields to use Java Optional on getter #913
Add 'javaOptional' extension rule to allow individual fields to use Java Optional on getter #913
Conversation
…fying to use optionals on a field level aswell as for the whole schema.
At the moment you can only specify using optionals on a global level, which is fine I guess but does lead to extra code where it sometimes isnt needed. This cange allows for both use on a global level, or specifying to use optional on a field level by providing "java_optional": true |
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.
Great. Thank you! I've added some review comments.
@@ -129,6 +129,24 @@ private boolean isRequired(String nodeName, JsonNode node, Schema schema) { | |||
return false; | |||
} | |||
|
|||
private boolean usesOptional(String nodeName, JsonNode node, Schema schema) { | |||
if (node.has("java_optional")) { |
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.
Could you rename these to javaOptional
, as this is the naming convention for our extension properties.
return requiredNode.asBoolean(); | ||
} | ||
|
||
JsonNode requiredArray = schema.getContent().get("java_optional"); |
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 think you mean javaOptionalArray
here? requiredArray
is a name which I assume was taken from another method.
@@ -77,7 +77,7 @@ public JDefinedClass apply(String nodeName, JsonNode node, JDefinedClass jclass, | |||
ruleFactory.getAnnotator().propertyField(field, jclass, nodeName, node); | |||
|
|||
if (isIncludeGetters) { | |||
JMethod getter = addGetter(jclass, field, nodeName, node, isRequired(nodeName, node, schema)); | |||
JMethod getter = addGetter(jclass, field, nodeName, node, isRequired(nodeName, node, schema), usesOptional(nodeName, node, schema)); |
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.
Could you name usesOptional
to useOptional
throughout? I think this scans better.
No probs. Review comments addressed. |
Change the Use Optionals for Getters functionality to allow for specifying to use optionals on a field level aswell as for the whole schema. Not a breaking change.