Skip to content

Conversation

mmolimar
Copy link

No description provided.

@lightbend-cla-validator
Copy link
Collaborator

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:

http://www.lightbend.com/contribute/cla

@mmolimar
Copy link
Author

Note: I have signed CLA.

Copy link
Contributor

@havocp havocp left a 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());
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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)

Copy link
Author

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));
Copy link
Contributor

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...)

Copy link
Author

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.

Copy link

@hemantkhurana hemantkhurana Nov 27, 2018

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)

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.

#541

@mmolimar
Copy link
Author

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.
For example, in other libs such as spray-json you can set a custom printer to do this (among other things).

@ennru
Copy link
Member

ennru commented Jul 6, 2023

We do not intend to extend the functionality of "Typesafe Config" further.
See https://github.com/lightbend/config#maintained-by

@ennru ennru closed this Jul 6, 2023
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.

5 participants