-
-
Couldn't load subscription status.
- Fork 233
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
Changes from 17 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
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
| import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
| import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
| import com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter; | ||
|
|
||
| public class XmlPrettyPrinterTest extends XmlTestBase | ||
| { | ||
|
|
@@ -176,7 +177,7 @@ public void testMultiLevel172() throws Exception | |
| .writeValueAsString(root); | ||
| // unify possible apostrophes to quotes | ||
| xml = a2q(xml); | ||
| // with indentation, should get linefeeds in prolog/epilog too | ||
|
|
||
| assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
| +"<Company>\n" | ||
| +" <e>\n" | ||
|
|
@@ -188,4 +189,75 @@ public void testMultiLevel172() throws Exception | |
| +"</Company>\n", | ||
| xml); | ||
| } | ||
|
|
||
| public void testNewLine_withCustomNewLine() throws Exception { | ||
| Company root = new Company(); | ||
| root.employee.add(new Employee("abc")); | ||
|
|
||
| String xml = _xmlMapper.writer() | ||
| .with(new DefaultXmlPrettyPrinter().withCustomNewLine("\n\rLF\n\r")) | ||
| .with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION) | ||
| .writeValueAsString(root); | ||
| // unify possible apostrophes to quotes | ||
| xml = a2q(xml); | ||
|
|
||
| // with indentation, should get newLines in prolog/epilog too | ||
| assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
|
||
| + "<Company>\n\rLF\n\r" | ||
| + " <e>\n\rLF\n\r" | ||
| + " <employee>\n\rLF\n\r" | ||
| + " <id>abc</id>\n\rLF\n\r" | ||
| + " <type>FULL_TIME</type>\n\rLF\n\r" | ||
| + " </employee>\n\rLF\n\r" | ||
| + " </e>\n\rLF\n\r" | ||
| + "</Company>\n", | ||
|
||
| xml); | ||
| } | ||
|
|
||
| public void testNewLine_systemDefault() throws Exception { | ||
| Company root = new Company(); | ||
| root.employee.add(new Employee("abc")); | ||
|
|
||
| String xml = _xmlMapper.writer() | ||
| .with(new DefaultXmlPrettyPrinter()) | ||
| .with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION) | ||
| .writeValueAsString(root); | ||
| // unify possible apostrophes to quotes | ||
| xml = a2q(xml); | ||
|
|
||
| // with indentation, should get newLines in prolog/epilog too | ||
| assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
|
||
| + "<Company>\n" | ||
| + " <e>\n" | ||
| + " <employee>\n" | ||
| + " <id>abc</id>\n" | ||
| + " <type>FULL_TIME</type>\n" | ||
| + " </employee>\n" | ||
| + " </e>\n" | ||
| + "</Company>\n", | ||
| xml); | ||
| } | ||
|
|
||
| public void testNewLine_UseSystemDefaultLineSeperatorOnNullCustomNewLine() throws Exception { | ||
| Company root = new Company(); | ||
| root.employee.add(new Employee("abc")); | ||
|
|
||
| String xml = _xmlMapper.writer() | ||
| .with(new DefaultXmlPrettyPrinter().withCustomNewLine(null)) | ||
| .with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION) | ||
| .writeValueAsString(root); | ||
| // unify possible apostrophes to quotes | ||
| xml = a2q(xml); | ||
|
|
||
| assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
| + "<Company>\n" | ||
| + " <e>\n" | ||
| + " <employee>\n" | ||
| + " <id>abc</id>\n" | ||
| + " <type>FULL_TIME</type>\n" | ||
| + " </employee>\n" | ||
| + " </e>\n" | ||
| + "</Company>\n", | ||
| xml); | ||
| } | ||
| } | ||
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.
Why not set
_newLinetoSYSTEM_DEFAULT_NEW_LINEifnullis passed? This would allow reverting back to system newline.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.
Agreed, I don't see any problem doing so.
done!