-
Notifications
You must be signed in to change notification settings - Fork 976
Render option to sort keys #557
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
Conversation
Hi @mmolimar, Thank you for your contribution! We really value the time you've taken to put this together. Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement: |
Note: I have signed CLA. |
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.
A couple detailed comments, before addressing those though, I think it'd be helpful to understand the motivation for this feature; what are you planning to use it for? Who else would use it do you think?
@@ -64,7 +69,7 @@ public ConfigRenderOptions setComments(boolean value) { | |||
if (value == comments) | |||
return this; | |||
else | |||
return new ConfigRenderOptions(originComments, value, formatted, json); | |||
return new ConfigRenderOptions(originComments, value, formatted, json, new DefaultComparator()); |
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.
These setters should be copying the existing comparator I believe. (otherwise setting anything other than the comparator would reset the comparator.) Meaning change new DefaultComparator()
to comparator
for all the set*
methods.
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.
Fixed
@@ -174,9 +204,53 @@ public String toString() { | |||
sb.append("formatted,"); | |||
if (json) | |||
sb.append("json,"); | |||
if (comparator != null) |
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.
is comparator actually allowed to be null? It looks to me like it isn't (it has to be DefaultComparator if not set explicitly)
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.
Changed
boolean aDigits = isAllDigits(a); | ||
boolean bDigits = isAllDigits(b); | ||
if (aDigits && bDigits) { | ||
return Integer.compare(Integer.parseInt(a), Integer.parseInt(b)); |
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 know you're copying this from our existing code, but I think this will throw if the digits make an integer greater than maxint. We probably ought to fix that... (in its own commit and maybe own PR...)
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.
You're totally right. I've changed that to BigInteger to avoid an exception.
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 believe I am hitting the exact same issue described here while rendering some config. Is this change part of the latest 1.3.3 release? I don't see it on the milestone page yet.
Exception in thread "main" java.lang.NumberFormatException: For input string: "10000951726339"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:583)
at java.lang.Integer.parseInt(Integer.java:615)
at com.typesafe.config.impl.SimpleConfigObject$RenderComparator.compare(SimpleConfigObject.java:452)
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 see it is a candidate for the next release. Please ignore the previous comment.
The idea to implement this is to allow the API to sort the keys in the order you like setting your custom comparator. In my case, I have to sort these keys in a specific order so that the rendered output has the same output as a template I have expects. |
We do not intend to extend the functionality of "Typesafe Config" further. |
No description provided.