@@ -33,7 +33,9 @@ public class DefaultPrettyPrinter
3333     * root values: a single space character. 
3434     * 
3535     * @since 2.1 
36+      * @deprecated in 2.16. Use the Separators API instead. 
3637     */ 
38+     @ Deprecated 
3739    public  final  static  SerializedString  DEFAULT_ROOT_VALUE_SEPARATOR  = new  SerializedString (" " );
3840
3941    /** 
@@ -70,16 +72,21 @@ public interface Indenter
7072
7173    /** 
7274     * String printed between root-level values, if any. 
75+      *  
76+      * @deprecated in 2.16. Use Separators API instead. 
7377     */ 
74-     protected  final   SerializableString  _rootSeparator ;
78+     protected  SerializableString  _rootSeparator ;
7579
7680    // // // Config, other white space configuration 
7781
7882    /** 
7983     * By default we will add spaces around colons used to 
8084     * separate object fields and values. 
8185     * If disabled, will not use spaces around colon. 
86+      *  
87+      * @deprecated in 2.16. Use Separators API instead. 
8288     */ 
89+     @ Deprecated 
8390    protected  boolean  _spacesInObjectEntries  = true ;
8491
8592    // // // State: 
@@ -99,15 +106,25 @@ public interface Indenter
99106     * @since 2.9 
100107     */ 
101108    protected  String  _objectFieldValueSeparatorWithSpaces ;
109+     
110+     /** 
111+      * @since 2.16 
112+      */ 
113+     protected  String  _objectEntrySeparator ;
102114
115+     /** 
116+      * @since 2.16 
117+      */ 
118+     protected  String  _arrayValueSeparator ;
119+     
103120    /* 
104121    /********************************************************** 
105122    /* Life-cycle (construct, configure) 
106123    /********************************************************** 
107124    */ 
108125
109126    public  DefaultPrettyPrinter () {
110-         this (DEFAULT_ROOT_VALUE_SEPARATOR );
127+         this (DEFAULT_SEPARATORS );
111128    }
112129
113130    /** 
@@ -118,7 +135,9 @@ public DefaultPrettyPrinter() {
118135     * calls {@link #DefaultPrettyPrinter(SerializableString)} 
119136     * 
120137     * @param rootSeparator String to use as root value separator 
138+      * @deprecated in 2.16. Use the Separators API instead. 
121139     */ 
140+     @ Deprecated 
122141    public  DefaultPrettyPrinter (String  rootSeparator ) {
123142        this ((rootSeparator  == null ) ? null  : new  SerializedString (rootSeparator ));
124143    }
@@ -128,16 +147,17 @@ public DefaultPrettyPrinter(String rootSeparator) {
128147     * if null, no separator is printed. 
129148     * 
130149     * @param rootSeparator String to use as root value separator 
150+      * @deprecated in 2.16. Use the Separators API instead. 
131151     */ 
152+     @ Deprecated 
132153    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 ()));
139155    }
140156
157+     /** 
158+      * @deprecated in 2.16. Use the Separators API instead. 
159+      */ 
160+     @ Deprecated 
141161    public  DefaultPrettyPrinter (DefaultPrettyPrinter  base ,
142162            SerializableString  rootSeparator )
143163    {
@@ -148,17 +168,58 @@ public DefaultPrettyPrinter(DefaultPrettyPrinter base,
148168
149169        _separators  = base ._separators ;
150170        _objectFieldValueSeparatorWithSpaces  = base ._objectFieldValueSeparatorWithSpaces ;
171+         _objectEntrySeparator  = base ._objectEntrySeparator ;
172+         _arrayValueSeparator  = base ._arrayValueSeparator ;
151173
152174        _rootSeparator  = rootSeparator ;
153175    }
154176
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 
155214    public  DefaultPrettyPrinter  withRootSeparator (SerializableString  rootSeparator )
156215    {
157216        if  (_rootSeparator  == rootSeparator  ||
158217                (rootSeparator  != null  && rootSeparator .equals (_rootSeparator ))) {
159218            return  this ;
160219        }
161-         return  new  DefaultPrettyPrinter (this , rootSeparator );
220+         Separators  separators  = _separators .withRootSeparator (rootSeparator  == null  ? null  : rootSeparator .getValue ());
221+         return  new  DefaultPrettyPrinter (this )
222+                 .withSeparators (separators );
162223    }
163224
164225    /** 
@@ -167,7 +228,9 @@ public DefaultPrettyPrinter withRootSeparator(SerializableString rootSeparator)
167228     * @return This pretty-printer instance (for call chaining) 
168229     * 
169230     * @since 2.6 
231+      * @deprecated in 2.16. Use the Separators API instead. 
170232     */ 
233+     @ Deprecated 
171234    public  DefaultPrettyPrinter  withRootSeparator (String  rootSeparator ) {
172235        return  withRootSeparator ((rootSeparator  == null ) ? null  : new  SerializedString (rootSeparator ));
173236    }
@@ -180,7 +243,7 @@ public void indentObjectsWith(Indenter i) {
180243        _objectIndenter  = (i  == null ) ? NopIndenter .instance  : i ;
181244    }
182245
183-     //  @since 2.3 
246+     /**  @since 2.3 */  
184247    public  DefaultPrettyPrinter  withArrayIndenter (Indenter  i ) {
185248        if  (i  == null ) {
186249            i  = NopIndenter .instance ;
@@ -193,7 +256,7 @@ public DefaultPrettyPrinter withArrayIndenter(Indenter i) {
193256        return  pp ;
194257    }
195258
196-     //  @since 2.3 
259+     /**  @since 2.3 */  
197260    public  DefaultPrettyPrinter  withObjectIndenter (Indenter  i ) {
198261        if  (i  == null ) {
199262            i  = NopIndenter .instance ;
@@ -215,7 +278,9 @@ public DefaultPrettyPrinter withObjectIndenter(Indenter i) {
215278     * @return This pretty-printer instance (for call chaining) 
216279     * 
217280     * @since 2.3 
281+      * @deprecated in 2.16. Use the Separators API instead. 
218282     */ 
283+     @ Deprecated 
219284    public  DefaultPrettyPrinter  withSpacesInObjectEntries () {
220285        return  _withSpaces (true );
221286    }
@@ -229,7 +294,9 @@ public DefaultPrettyPrinter withSpacesInObjectEntries() {
229294     * @return This pretty-printer instance (for call chaining) 
230295     * 
231296     * @since 2.3 
297+      * @deprecated in 2.16. Use the Separators API instead. 
232298     */ 
299+     @ Deprecated 
233300    public  DefaultPrettyPrinter  withoutSpacesInObjectEntries () {
234301        return  _withSpaces (false );
235302    }
@@ -239,7 +306,9 @@ protected DefaultPrettyPrinter _withSpaces(boolean state)
239306        if  (_spacesInObjectEntries  == state ) {
240307            return  this ;
241308        }
242-         DefaultPrettyPrinter  pp  = new  DefaultPrettyPrinter (this );
309+         
310+         Separators  copy  = _separators .withObjectFieldValueSpacing (state  ? Separators .Spacing .BOTH  : Separators .Spacing .NONE );
311+         DefaultPrettyPrinter  pp  = withSeparators (copy );
243312        pp ._spacesInObjectEntries  = state ;
244313        return  pp ;
245314    }
@@ -254,9 +323,16 @@ protected DefaultPrettyPrinter _withSpaces(boolean state)
254323     * @since 2.9 
255324     */ 
256325    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 ;
260336    }
261337
262338    /* 
@@ -315,11 +391,7 @@ public void beforeObjectEntries(JsonGenerator g) throws IOException
315391    @ Override 
316392    public  void  writeObjectFieldValueSeparator (JsonGenerator  g ) throws  IOException 
317393    {
318-         if  (_spacesInObjectEntries ) {
319-             g .writeRaw (_objectFieldValueSeparatorWithSpaces );
320-         } else  {
321-             g .writeRaw (_separators .getObjectFieldValueSeparator ());
322-         }
394+         g .writeRaw (_objectFieldValueSeparatorWithSpaces );
323395    }
324396
325397    /** 
@@ -334,7 +406,7 @@ public void writeObjectFieldValueSeparator(JsonGenerator g) throws IOException
334406    @ Override 
335407    public  void  writeObjectEntrySeparator (JsonGenerator  g ) throws  IOException 
336408    {
337-         g .writeRaw (_separators . getObjectEntrySeparator () );
409+         g .writeRaw (_objectEntrySeparator );
338410        _objectIndenter .writeIndentation (g , _nesting );
339411    }
340412
@@ -378,7 +450,7 @@ public void beforeArrayValues(JsonGenerator g) throws IOException {
378450    @ Override 
379451    public  void  writeArrayValueSeparator (JsonGenerator  g ) throws  IOException 
380452    {
381-         g .writeRaw (_separators . getArrayValueSeparator () );
453+         g .writeRaw (_arrayValueSeparator );
382454        _arrayIndenter .writeIndentation (g , _nesting );
383455    }
384456
0 commit comments