File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
main/java/org/metafacture/json
test/java/org/metafacture/json Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 3434import com .fasterxml .jackson .core .SerializableString ;
3535import com .fasterxml .jackson .core .io .CharacterEscapes ;
3636import com .fasterxml .jackson .core .io .SerializedString ;
37+ import com .fasterxml .jackson .core .util .DefaultPrettyPrinter ;
3738
3839/**
3940 * Serialises an object as JSON. Records and entities are represented
@@ -66,11 +67,7 @@ public JsonEncoder() {
6667 }
6768
6869 public void setPrettyPrinting (final boolean prettyPrinting ) {
69- if (prettyPrinting ) {
70- jsonGenerator .useDefaultPrettyPrinter ();
71- } else {
72- jsonGenerator .setPrettyPrinter (null );
73- }
70+ jsonGenerator .setPrettyPrinter (prettyPrinting ? new DefaultPrettyPrinter ((SerializableString ) null ) : null );
7471 }
7572
7673 public boolean getPrettyPrinting () {
Original file line number Diff line number Diff line change @@ -181,6 +181,22 @@ public void testIssue152ShouldNotPrefixOutputWithSpaces() {
181181 ordered .verify (receiver ).process (fixQuotes ("{'L2':'V2'}" ));
182182 }
183183
184+ @ Test
185+ public void testShouldNotPrefixPrettyPrintedOutputWithSpaces () {
186+ encoder .setPrettyPrinting (true );
187+
188+ encoder .startRecord ("" );
189+ encoder .literal (LITERAL1 , VALUE1 );
190+ encoder .endRecord ();
191+ encoder .startRecord ("" );
192+ encoder .literal (LITERAL2 , VALUE2 );
193+ encoder .endRecord ();
194+
195+ final InOrder ordered = inOrder (receiver );
196+ ordered .verify (receiver ).process (fixQuotes ("{\n 'L1' : 'V1'\n }" ));
197+ ordered .verify (receiver ).process (fixQuotes ("{\n 'L2' : 'V2'\n }" ));
198+ }
199+
184200 /*
185201 * Utility method which replaces all single quotes in a string with double quotes.
186202 * This allows to specify the JSON output in the test cases without having to wrap
You can’t perform that action at this time.
0 commit comments