-
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
(#706) : Default value for property of "integer enum" type caused POJ… #709
Conversation
…pe caused POJO compilation error
…pe caused POJO compilation error
@s13o Is it not possible to use |
The 'getDefaultEnum' is not a new method actually. It was introduced since the first revision of the 'DefaultRule' class. The method "getDefaultValue" has used it to resolve the 'JExpression' for 'default value of Enum' even before my changes. |
|
||
JInvocation invokeFromValue = fieldType.staticInvoke(EnumRule.FROM_VALUE_METHOD_NAME); | ||
JType paramType = getParameterType(fieldType, EnumRule.FROM_VALUE_METHOD_NAME).unboxify(); | ||
if (paramType == paramType.owner().INT) { |
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 mean instead of this code here, you should be able to re-use getDefaultValue
and not duplicate the if
/else if
block.
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 prefere not to write spaghetti-code with dozens of if-else at all.
But you proposed me to move some more if-else from getDefaultEnum
to 'getDefaultValue' and delete the getDefaultEnum
method after that, is not it?
Well, not bad idea to remove the getDefaultEnum
but I'll better use some AbstractFactory pattern right from the top apply
method for this instead of if-else.
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.
@s13o Sorry, this conversation is getting very confused.
I originally added a comment here:
#707 (comment)
What I'm saying is: there is no need to duplicate if
/else
blocks from getDefaultValue
into getDefaultEnum
. The getDefaultEnum
method can call getDefaultValue
if I am not mistaken. Inside getDefaultEnum
(line 269) you have JType paramType
, you have JsonNode node
and you need a JExpression
result. You have everything you need on line 269 to call getDefaultValue
instead of implementing a duplicate if
/else
block.
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.
Man, the conversation is beautiful!
I understood your idea, it is reasonable because signatures of both methods are more or less similar. And right after that I've seen that adding some more if-else into the getDefaultValue
is a crime :)
Much more clever is to use something like getFactory(JType::type).apply(JsonNode::node)
.
I'll check later how to make it easy :)
Also I'll check your idea about recursion
Regards!
…pe caused POJO compilation error
…pe caused POJO compilation error
@s13o I appreciate you getting involved here but I simply can't bring myself to merge an additional 700 lines of code into this project to fix this problem. There's a simple Sorry if this feels very negative, it's not my intention to be difficult for its own sake. I can take a look at solving #706 soon and see if I can find a different solution and in the meantime you are free to use a version built from your own fork. |
There are ~500 lines of tests were added. P.S. |
Closed by #713. |
Also added support for boolean & double (number), in accordance with reference