Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feature : Allow setting custom linefeed on DefaultXmlPrettyPrinter #568
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
Feature : Allow setting custom linefeed on DefaultXmlPrettyPrinter #568
Changes from 10 commits
374e125
eb23bbd
c0b3e41
3b066cb
8595328
79564a4
f515eba
4cc4394
6974014
b75bfdd
18abcc2
c764189
af70ece
7deeb84
8360276
6187f3d
d0aaf64
29a2bbf
fc4fb17
dd198f2
b43811c
05b1f04
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Let's just catch
Exception
, notThrowable
(ok unlike we'd get OOME or such but as a general good practice)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.
late reply, but done 👍🏻
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.
can you remove this comment?
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 :)
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.
Same here, keep
static
(no need to refer to enclosing class)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 am not sure if this line should end with customLineFeed instead of `\n?
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.
see the answer to your follow up question
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 am not sure if this line should end with customLineFeed instead of `\n?
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.
yes - all the line feeds should be the same
actually, could we rename the method as
withCustomNewLine
? - I don't think 'line feed' is a good name for this property at all - 'new line' is betterThere 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.
noted will make sure tests are applied there?
Agreed and I will change names as below!🙏🏼
_lineFeed
->_newLine
DEFAULT_LINE_FEED
->SYSTEM_DEFAULT_NEW_LINE
withCustomLineFeed
->withCustomNewLine
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.
@pjfanning So here is an update.
Done.
All names are changed from 'line feed' to 'new line'
May I get your opinion here? It seems like writing custom 'new lines' before and after root element might be out of this PR's scope. The 'new lines' before and after the root element are written by method
writePrologLinefeed()
of another instance ofDefaultXmlPrettyPrinter
.This instance invoking
writePrologLinefeed()
instance seems to be initialized and used inside ToXmlGenerator which we cannot hook into from neitherXmlMapper().setDefaultPrettyPrinter()
norObjectWriter.with(PrettyPrinter)
.For references,
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.
It makes little sense to me not to use the same new lines throughout the XML doc. I'm now -1 on this 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.
@JooHyukKim Ok that sounds like a problem indeed! I wonder if it's the case of
Indenter
instance not being created yet (withcreateInstance()
) or what is happening.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.
Not the indenter, actually. There is a separate instance of
DefaultXmlPrettyPrinter
initialized together withToXmlGenerator
that invokes_xmlPrettyPrinter.writePrologLinefeed
to write prolog and epilog.You can refer to below to code lines.
My first (probable) observation is that writing prolog and epilog with instance of
DefaultXmlPrettyPrinter
I mentioned above seems NOT to be overridden byObjectMapper.setDefaultPrettyPrinter(PrettyPrinter)
norObjectWriter.with(PrettyPrinter)
.Second observation is
ToXmlGenerator
writes prolog during the process of initialization withinToXmlGenerator.initGenerator
method.It will be great, @cowtowncoder if you can help out a little here? To override DefaultXmlPrettyPrinter of
ToXmlGenerator._xmlPrettyPrinter
before it writes prolog and epilog?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.
Right, pretty printer instance. I will try to see if I can figure it out -- the problem is that XML module extends basic
PrettyPrinter
API to its needs but databind still tries to orchestrate handling. So I will try to see if I can figure out how to avoid there being different instance being used.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.
@JooHyukKim Ah. Part of the problem is that you haven't updated copy constructor:
to copy
_newLine
property -- so when methodis called the new instance "forgets"
_newLine
. So you need to addin that constructor.
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.
Woooooow thank you for helping out 🥹 @cowtowncoder
How did I miss that!
Done 🙏🏼
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.
Need to replace
\n
with system linefeed so test passes on Windows systems too.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.
Right, done! 🙏🏼
And plus I checked other similar test cases' assertions and some hard coded
\n
as system linefeed.@cowtowncoder if you agree, I will make a separate PR on "replacing all hard coded
\n
to the value read fromSystem.getProperty("line.separator");
"?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.
Yeah sounds good wrt hard-coded linefeeds