@@ -33,7 +33,9 @@ public class DefaultPrettyPrinter
33
33
* root values: a single space character.
34
34
*
35
35
* @since 2.1
36
+ * @deprecated in 2.16. Use the Separators API instead.
36
37
*/
38
+ @ Deprecated
37
39
public final static SerializedString DEFAULT_ROOT_VALUE_SEPARATOR = new SerializedString (" " );
38
40
39
41
/**
@@ -70,16 +72,21 @@ public interface Indenter
70
72
71
73
/**
72
74
* String printed between root-level values, if any.
75
+ *
76
+ * @deprecated in 2.16. Use Separators API instead.
73
77
*/
74
- protected final SerializableString _rootSeparator ;
78
+ protected SerializableString _rootSeparator ;
75
79
76
80
// // // Config, other white space configuration
77
81
78
82
/**
79
83
* By default we will add spaces around colons used to
80
84
* separate object fields and values.
81
85
* If disabled, will not use spaces around colon.
86
+ *
87
+ * @deprecated in 2.16. Use Separators API instead.
82
88
*/
89
+ @ Deprecated
83
90
protected boolean _spacesInObjectEntries = true ;
84
91
85
92
// // // State:
@@ -99,15 +106,25 @@ public interface Indenter
99
106
* @since 2.9
100
107
*/
101
108
protected String _objectFieldValueSeparatorWithSpaces ;
109
+
110
+ /**
111
+ * @since 2.16
112
+ */
113
+ protected String _objectEntrySeparator ;
102
114
115
+ /**
116
+ * @since 2.16
117
+ */
118
+ protected String _arrayValueSeparator ;
119
+
103
120
/*
104
121
/**********************************************************
105
122
/* Life-cycle (construct, configure)
106
123
/**********************************************************
107
124
*/
108
125
109
126
public DefaultPrettyPrinter () {
110
- this (DEFAULT_ROOT_VALUE_SEPARATOR );
127
+ this (DEFAULT_SEPARATORS );
111
128
}
112
129
113
130
/**
@@ -118,7 +135,9 @@ public DefaultPrettyPrinter() {
118
135
* calls {@link #DefaultPrettyPrinter(SerializableString)}
119
136
*
120
137
* @param rootSeparator String to use as root value separator
138
+ * @deprecated in 2.16. Use the Separators API instead.
121
139
*/
140
+ @ Deprecated
122
141
public DefaultPrettyPrinter (String rootSeparator ) {
123
142
this ((rootSeparator == null ) ? null : new SerializedString (rootSeparator ));
124
143
}
@@ -128,16 +147,17 @@ public DefaultPrettyPrinter(String rootSeparator) {
128
147
* if null, no separator is printed.
129
148
*
130
149
* @param rootSeparator String to use as root value separator
150
+ * @deprecated in 2.16. Use the Separators API instead.
131
151
*/
152
+ @ Deprecated
132
153
public DefaultPrettyPrinter (SerializableString rootSeparator ) {
133
- _rootSeparator = rootSeparator ;
134
- withSeparators (DEFAULT_SEPARATORS );
135
- }
136
-
137
- public DefaultPrettyPrinter (DefaultPrettyPrinter base ) {
138
- this (base , base ._rootSeparator );
154
+ this (DEFAULT_SEPARATORS .withRootSeparator (rootSeparator .getValue ()));
139
155
}
140
156
157
+ /**
158
+ * @deprecated in 2.16. Use the Separators API instead.
159
+ */
160
+ @ Deprecated
141
161
public DefaultPrettyPrinter (DefaultPrettyPrinter base ,
142
162
SerializableString rootSeparator )
143
163
{
@@ -148,17 +168,58 @@ public DefaultPrettyPrinter(DefaultPrettyPrinter base,
148
168
149
169
_separators = base ._separators ;
150
170
_objectFieldValueSeparatorWithSpaces = base ._objectFieldValueSeparatorWithSpaces ;
171
+ _objectEntrySeparator = base ._objectEntrySeparator ;
172
+ _arrayValueSeparator = base ._arrayValueSeparator ;
151
173
152
174
_rootSeparator = rootSeparator ;
153
175
}
154
176
177
+ /**
178
+ * @since 2.16
179
+ */
180
+ public DefaultPrettyPrinter (Separators separators )
181
+ {
182
+ _separators = separators ;
183
+
184
+ _rootSeparator = separators .getRootSeparator () == null ? null : new SerializedString (separators .getRootSeparator ());
185
+ _objectFieldValueSeparatorWithSpaces = separators .getObjectFieldValueSpacing ().apply (
186
+ separators .getObjectFieldValueSeparator ());
187
+ _objectEntrySeparator = separators .getObjectEntrySpacing ().apply (separators .getObjectEntrySeparator ());
188
+ _arrayValueSeparator = separators .getArrayValueSpacing ().apply (separators .getArrayValueSeparator ());
189
+ }
190
+
191
+ /**
192
+ * Copy constructor
193
+ *
194
+ * @since 2.16
195
+ */
196
+ public DefaultPrettyPrinter (DefaultPrettyPrinter base ) {
197
+ _rootSeparator = base ._rootSeparator ;
198
+
199
+ _arrayIndenter = base ._arrayIndenter ;
200
+ _objectIndenter = base ._objectIndenter ;
201
+ _spacesInObjectEntries = base ._spacesInObjectEntries ;
202
+ _nesting = base ._nesting ;
203
+
204
+ _separators = base ._separators ;
205
+ _objectFieldValueSeparatorWithSpaces = base ._objectFieldValueSeparatorWithSpaces ;
206
+ _objectEntrySeparator = base ._objectEntrySeparator ;
207
+ _arrayValueSeparator = base ._arrayValueSeparator ;
208
+ }
209
+
210
+ /**
211
+ * @deprecated in 2.16. Use the Separators API instead.
212
+ */
213
+ @ Deprecated
155
214
public DefaultPrettyPrinter withRootSeparator (SerializableString rootSeparator )
156
215
{
157
216
if (_rootSeparator == rootSeparator ||
158
217
(rootSeparator != null && rootSeparator .equals (_rootSeparator ))) {
159
218
return this ;
160
219
}
161
- return new DefaultPrettyPrinter (this , rootSeparator );
220
+ Separators separators = _separators .withRootSeparator (rootSeparator == null ? null : rootSeparator .getValue ());
221
+ return new DefaultPrettyPrinter (this )
222
+ .withSeparators (separators );
162
223
}
163
224
164
225
/**
@@ -167,7 +228,9 @@ public DefaultPrettyPrinter withRootSeparator(SerializableString rootSeparator)
167
228
* @return This pretty-printer instance (for call chaining)
168
229
*
169
230
* @since 2.6
231
+ * @deprecated in 2.16. Use the Separators API instead.
170
232
*/
233
+ @ Deprecated
171
234
public DefaultPrettyPrinter withRootSeparator (String rootSeparator ) {
172
235
return withRootSeparator ((rootSeparator == null ) ? null : new SerializedString (rootSeparator ));
173
236
}
@@ -180,7 +243,7 @@ public void indentObjectsWith(Indenter i) {
180
243
_objectIndenter = (i == null ) ? NopIndenter .instance : i ;
181
244
}
182
245
183
- // @since 2.3
246
+ /** @since 2.3 */
184
247
public DefaultPrettyPrinter withArrayIndenter (Indenter i ) {
185
248
if (i == null ) {
186
249
i = NopIndenter .instance ;
@@ -193,7 +256,7 @@ public DefaultPrettyPrinter withArrayIndenter(Indenter i) {
193
256
return pp ;
194
257
}
195
258
196
- // @since 2.3
259
+ /** @since 2.3 */
197
260
public DefaultPrettyPrinter withObjectIndenter (Indenter i ) {
198
261
if (i == null ) {
199
262
i = NopIndenter .instance ;
@@ -215,7 +278,9 @@ public DefaultPrettyPrinter withObjectIndenter(Indenter i) {
215
278
* @return This pretty-printer instance (for call chaining)
216
279
*
217
280
* @since 2.3
281
+ * @deprecated in 2.16. Use the Separators API instead.
218
282
*/
283
+ @ Deprecated
219
284
public DefaultPrettyPrinter withSpacesInObjectEntries () {
220
285
return _withSpaces (true );
221
286
}
@@ -229,7 +294,9 @@ public DefaultPrettyPrinter withSpacesInObjectEntries() {
229
294
* @return This pretty-printer instance (for call chaining)
230
295
*
231
296
* @since 2.3
297
+ * @deprecated in 2.16. Use the Separators API instead.
232
298
*/
299
+ @ Deprecated
233
300
public DefaultPrettyPrinter withoutSpacesInObjectEntries () {
234
301
return _withSpaces (false );
235
302
}
@@ -239,7 +306,9 @@ protected DefaultPrettyPrinter _withSpaces(boolean state)
239
306
if (_spacesInObjectEntries == state ) {
240
307
return this ;
241
308
}
242
- DefaultPrettyPrinter pp = new DefaultPrettyPrinter (this );
309
+
310
+ Separators copy = _separators .withObjectFieldValueSpacing (state ? Separators .Spacing .BOTH : Separators .Spacing .NONE );
311
+ DefaultPrettyPrinter pp = withSeparators (copy );
243
312
pp ._spacesInObjectEntries = state ;
244
313
return pp ;
245
314
}
@@ -254,9 +323,16 @@ protected DefaultPrettyPrinter _withSpaces(boolean state)
254
323
* @since 2.9
255
324
*/
256
325
public DefaultPrettyPrinter withSeparators (Separators separators ) {
257
- _separators = separators ;
258
- _objectFieldValueSeparatorWithSpaces = " " + separators .getObjectFieldValueSeparator () + " " ;
259
- return this ;
326
+ DefaultPrettyPrinter result = new DefaultPrettyPrinter (this );
327
+ result ._separators = separators ;
328
+
329
+ result ._rootSeparator = separators .getRootSeparator () == null ? null : new SerializedString (separators .getRootSeparator ());
330
+ result ._objectFieldValueSeparatorWithSpaces = separators .getObjectFieldValueSpacing ().apply (
331
+ separators .getObjectFieldValueSeparator ());
332
+ result ._objectEntrySeparator = separators .getObjectEntrySpacing ().apply (separators .getObjectEntrySeparator ());
333
+ result ._arrayValueSeparator = separators .getArrayValueSpacing ().apply (separators .getArrayValueSeparator ());
334
+
335
+ return result ;
260
336
}
261
337
262
338
/*
@@ -315,11 +391,7 @@ public void beforeObjectEntries(JsonGenerator g) throws IOException
315
391
@ Override
316
392
public void writeObjectFieldValueSeparator (JsonGenerator g ) throws IOException
317
393
{
318
- if (_spacesInObjectEntries ) {
319
- g .writeRaw (_objectFieldValueSeparatorWithSpaces );
320
- } else {
321
- g .writeRaw (_separators .getObjectFieldValueSeparator ());
322
- }
394
+ g .writeRaw (_objectFieldValueSeparatorWithSpaces );
323
395
}
324
396
325
397
/**
@@ -334,7 +406,7 @@ public void writeObjectFieldValueSeparator(JsonGenerator g) throws IOException
334
406
@ Override
335
407
public void writeObjectEntrySeparator (JsonGenerator g ) throws IOException
336
408
{
337
- g .writeRaw (_separators . getObjectEntrySeparator () );
409
+ g .writeRaw (_objectEntrySeparator );
338
410
_objectIndenter .writeIndentation (g , _nesting );
339
411
}
340
412
@@ -378,7 +450,7 @@ public void beforeArrayValues(JsonGenerator g) throws IOException {
378
450
@ Override
379
451
public void writeArrayValueSeparator (JsonGenerator g ) throws IOException
380
452
{
381
- g .writeRaw (_separators . getArrayValueSeparator () );
453
+ g .writeRaw (_arrayValueSeparator );
382
454
_arrayIndenter .writeIndentation (g , _nesting );
383
455
}
384
456
0 commit comments