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 34
34
import com .fasterxml .jackson .core .SerializableString ;
35
35
import com .fasterxml .jackson .core .io .CharacterEscapes ;
36
36
import com .fasterxml .jackson .core .io .SerializedString ;
37
+ import com .fasterxml .jackson .core .util .DefaultPrettyPrinter ;
37
38
38
39
/**
39
40
* Serialises an object as JSON. Records and entities are represented
@@ -66,11 +67,7 @@ public JsonEncoder() {
66
67
}
67
68
68
69
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 );
74
71
}
75
72
76
73
public boolean getPrettyPrinting () {
Original file line number Diff line number Diff line change @@ -181,6 +181,22 @@ public void testIssue152ShouldNotPrefixOutputWithSpaces() {
181
181
ordered .verify (receiver ).process (fixQuotes ("{'L2':'V2'}" ));
182
182
}
183
183
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
+
184
200
/*
185
201
* Utility method which replaces all single quotes in a string with double quotes.
186
202
* 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