-
-
Notifications
You must be signed in to change notification settings - Fork 797
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
Allow configuring spaces before and/or after the colon in DefaultPrettyPrinter
#1042
Allow configuring spaces before and/or after the colon in DefaultPrettyPrinter
#1042
Conversation
I tried to keep the behavior the same but looking at the broken unit tests, this approach doesn't work very well. Suggestions how to proceed? Change the tests and risk breaking existing code or create a new, parallel API and deprecate the old ones? |
Yeah this is tricky; whether it's possible to change, in a backwards-compatible way, behavior of I would probably implement alternate Alternatively if you do want to try to change |
My second idea was to add a boolean I think a cleaner approach would be when |
@digulla Yeah, apologies for the mess here: division of responsibilities is not well defined for sure. I hope we can figure this out. Ability to include space before and/or after colon sounds like reasonable if it's possible to retro-fit somehow. I assume at least 3 out of 4 combinations would be widely enough used. |
@digulla Ok, looking at Now, whether "full" value should be indicated by String containing space, enumeration (4 combinations for pre-/after of single space), or 2 boolean flags per settings I don't know. It might be simplest to just add full String to keep number of settings limited. Maybe I could try outlining how I see this working unless you get there first. EDIT: although, TBH, adding configuration in |
I also think we could have a boolean flag which controls the space before the colon but it would make the code even more confusing than it already is. How about a new implementation for both and deprecating the old ones for 3.x? I would use |
This one is much cleaner than the first attempt but we have to decide which PrettyPrinter config to break: Either the default Separators is with spaces around the colon, then MinimalPrettyPrinter has to modify the default. Or the default is without spaces, then DefaultPrettyPrinter has to modify it. Of course, this affects anyone who tries to build their own PrettyPrinter using the default Separators.
I've rolled back the incompatible changes and introduced a new Spacing enum. This allows for much cleaner code but one of Right now, I think is the way to go. |
@@ -255,7 +255,8 @@ protected DefaultPrettyPrinter _withSpaces(boolean state) | |||
*/ | |||
public DefaultPrettyPrinter withSeparators(Separators separators) { | |||
_separators = separators; | |||
_objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " "; | |||
_objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSpacing().apply( |
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.
For performance reasons, let's also add the other 2 "WithSpaces" fields that are missing to avoid calling apply()
on those cases.
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.
Done
@digulla I agree this is the way to go. We do need to eliminate calls to I am hoping to get this merged soon, thank you for working through all the ideas here. |
Deprecated old API. Tests for old and new API to make sure the changes don't break existing code and the new API can do what the old could.
Okay, I feel we're making progress. Have a look at the latest version. It should address all your concerns. I'm not sure what to do with SerializedString used only for rootSeparator. String is already perfectly serializable; what is the purpose of this class? Should I always use SerializedString? But then, why do the existing fields in DefaultPrettyPrinter mix String and SerializedString? |
Converted all tests that used the old API.
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.
Looks good -- I hope I can figure out how to merge it in master/3.0.
DefaultPrettyPrinter
Ok, merged up to |
Hey, thanks. It was nice working with you on this. |
@digulla My pleasure, thank you for going through twists & turns :) |
No description provided.