@@ -265,7 +265,17 @@ public static int collectDefaults() {
265
265
* @since 2.1
266
266
*/
267
267
protected SerializableString _rootValueSeparator = DEFAULT_ROOT_VALUE_SEPARATOR ;
268
-
268
+
269
+ /**
270
+ * Optional threshold used for automatically escaping character above certain character
271
+ * code value: either {@code 0} to indicate that no threshold is specified, or value
272
+ * at or above 127 to indicate last character code that is NOT automatically escaped
273
+ * (but depends on other configuration rules for checking).
274
+ *
275
+ * @since 2.10
276
+ */
277
+ protected int _maximumNonEscapedChar ;
278
+
269
279
/*
270
280
/**********************************************************
271
281
/* Construction
@@ -301,11 +311,7 @@ protected JsonFactory(JsonFactory src, ObjectCodec codec)
301
311
_inputDecorator = src ._inputDecorator ;
302
312
_outputDecorator = src ._outputDecorator ;
303
313
_rootValueSeparator = src ._rootValueSeparator ;
304
-
305
- /* 27-Apr-2013, tatu: How about symbol table; should we try to
306
- * reuse shared symbol tables? Could be more efficient that way;
307
- * although can slightly add to concurrency overhead.
308
- */
314
+ _maximumNonEscapedChar = src ._maximumNonEscapedChar ;
309
315
}
310
316
311
317
/**
@@ -317,6 +323,7 @@ public JsonFactory(JsonFactoryBuilder b) {
317
323
this (b , false );
318
324
_characterEscapes = b ._characterEscapes ;
319
325
_rootValueSeparator = b ._rootValueSeparator ;
326
+ _maximumNonEscapedChar = b ._maximumNonEscapedChar ;
320
327
}
321
328
322
329
/**
@@ -334,6 +341,8 @@ protected JsonFactory(TSFBuilder<?,?> b, boolean bogus) {
334
341
_generatorFeatures = b ._streamWriteFeatures ;
335
342
_inputDecorator = b ._inputDecorator ;
336
343
_outputDecorator = b ._outputDecorator ;
344
+ // NOTE: missing _maximumNonEscapedChar since that's only in JsonFactoryBuilder
345
+ _maximumNonEscapedChar = 0 ;
337
346
}
338
347
339
348
/**
@@ -1524,6 +1533,9 @@ protected JsonGenerator _createGenerator(Writer out, IOContext ctxt) throws IOEx
1524
1533
{
1525
1534
WriterBasedJsonGenerator gen = new WriterBasedJsonGenerator (ctxt ,
1526
1535
_generatorFeatures , _objectCodec , out );
1536
+ if (_maximumNonEscapedChar > 0 ) {
1537
+ gen .setHighestNonEscapedChar (_maximumNonEscapedChar );
1538
+ }
1527
1539
if (_characterEscapes != null ) {
1528
1540
gen .setCharacterEscapes (_characterEscapes );
1529
1541
}
@@ -1547,6 +1559,9 @@ protected JsonGenerator _createGenerator(Writer out, IOContext ctxt) throws IOEx
1547
1559
protected JsonGenerator _createUTF8Generator (OutputStream out , IOContext ctxt ) throws IOException {
1548
1560
UTF8JsonGenerator gen = new UTF8JsonGenerator (ctxt ,
1549
1561
_generatorFeatures , _objectCodec , out );
1562
+ if (_maximumNonEscapedChar > 0 ) {
1563
+ gen .setHighestNonEscapedChar (_maximumNonEscapedChar );
1564
+ }
1550
1565
if (_characterEscapes != null ) {
1551
1566
gen .setCharacterEscapes (_characterEscapes );
1552
1567
}
0 commit comments