Skip to content

Commit a2e846e

Browse files
committed
... and yet more
1 parent 1d63a6b commit a2e846e

10 files changed

+88
-52
lines changed

src/main/java/com/fasterxml/jackson/core/JsonParser.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ public enum Feature {
9898
* Since JSON specification requires use of double quotes for
9999
* field names,
100100
* this is a non-standard feature, and as such disabled by default.
101+
*
102+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_UNQUOTED_FIELD_NAMES} instead
101103
*/
104+
@Deprecated
102105
ALLOW_UNQUOTED_FIELD_NAMES(false),
103106

104107
/**
@@ -111,7 +114,10 @@ public enum Feature {
111114
* Since JSON specification requires use of double quotes for
112115
* field names,
113116
* this is a non-standard feature, and as such disabled by default.
117+
*
118+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_SINGLE_QUOTES} instead
114119
*/
120+
@Deprecated
115121
ALLOW_SINGLE_QUOTES(false),
116122

117123
/**
@@ -125,7 +131,7 @@ public enum Feature {
125131
* Since JSON specification requires quoting for all control characters,
126132
* this is a non-standard feature, and as such disabled by default.
127133
*
128-
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER} instead
134+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_UNESCAPED_CONTROL_CHARS} instead
129135
*/
130136
@Deprecated
131137
ALLOW_UNQUOTED_CONTROL_CHARS(false),

src/main/java/com/fasterxml/jackson/core/json/JsonReadFeature.java

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public enum JsonReadFeature
5353
* field names,
5454
* this is a non-standard feature, and as such disabled by default.
5555
*/
56+
@SuppressWarnings("deprecation")
5657
ALLOW_SINGLE_QUOTES(false, JsonParser.Feature.ALLOW_SINGLE_QUOTES),
5758

5859
/**
@@ -64,6 +65,7 @@ public enum JsonReadFeature
6465
* field names,
6566
* this is a non-standard feature, and as such disabled by default.
6667
*/
68+
@SuppressWarnings("deprecation")
6769
ALLOW_UNQUOTED_FIELD_NAMES(false, JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES),
6870

6971
/**

src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ public class ReaderBasedJsonParser // final in 2.3, earlier
2727

2828
@SuppressWarnings("deprecation")
2929
private final static int FEAT_MASK_NON_NUM_NUMBERS = Feature.ALLOW_NON_NUMERIC_NUMBERS.getMask();
30-
30+
31+
@SuppressWarnings("deprecation")
32+
private final static int FEAT_MASK_ALLOW_MISSING = Feature.ALLOW_MISSING_VALUES.getMask();
33+
@SuppressWarnings("deprecation")
34+
private final static int FEAT_MASK_ALLOW_SINGLE_QUOTES = Feature.ALLOW_SINGLE_QUOTES.getMask();
35+
@SuppressWarnings("deprecation")
36+
private final static int FEAT_MASK_ALLOW_UNQUOTED_NAMES = Feature.ALLOW_UNQUOTED_FIELD_NAMES.getMask();
37+
3138
// Latin1 encoding is not supported, but we do use 8-bit subset for
3239
// pre-processing task, to simplify first pass, keep it fast.
3340
protected final static int[] _icLatin1 = CharTypes.getInputCodeLatin1();
@@ -1124,7 +1131,7 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
11241131
*/
11251132
case ',':
11261133
case ']':
1127-
if (isEnabled(Feature.ALLOW_MISSING_VALUES)) {
1134+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
11281135
--_inputPtr;
11291136
return (_currToken = JsonToken.VALUE_NULL);
11301137
}
@@ -1757,11 +1764,11 @@ private String _parseName2(int startPtr, int hash, int endChar) throws IOExcepti
17571764
protected String _handleOddName(int i) throws IOException
17581765
{
17591766
// [JACKSON-173]: allow single quotes
1760-
if (i == '\'' && isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
1767+
if (i == '\'' && (_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) {
17611768
return _parseAposName();
17621769
}
17631770
// [JACKSON-69]: allow unquoted names if feature enabled:
1764-
if (!isEnabled(Feature.ALLOW_UNQUOTED_FIELD_NAMES)) {
1771+
if ((_features & FEAT_MASK_ALLOW_UNQUOTED_NAMES) == 0) {
17651772
_reportUnexpectedChar(i, "was expecting double-quote to start field name");
17661773
}
17671774
final int[] codes = CharTypes.getInputCodeLatin1JsNames();
@@ -1851,7 +1858,7 @@ protected JsonToken _handleOddValue(int i) throws IOException
18511858
* Also, no separation to fast/slow parsing; we'll just do
18521859
* one regular (~= slowish) parsing, to keep code simple
18531860
*/
1854-
if (isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
1861+
if ((_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) {
18551862
return _handleApos();
18561863
}
18571864
break;
@@ -1865,7 +1872,7 @@ protected JsonToken _handleOddValue(int i) throws IOException
18651872
}
18661873
// fall through
18671874
case ',':
1868-
if (isEnabled(Feature.ALLOW_MISSING_VALUES)) {
1875+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
18691876
--_inputPtr;
18701877
return JsonToken.VALUE_NULL;
18711878
}

src/main/java/com/fasterxml/jackson/core/json/UTF8DataInputJsonParser.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public class UTF8DataInputJsonParser
4343
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
4444
@SuppressWarnings("deprecation")
4545
private final static int FEAT_MASK_NON_NUM_NUMBERS = Feature.ALLOW_NON_NUMERIC_NUMBERS.getMask();
46+
@SuppressWarnings("deprecation")
47+
private final static int FEAT_MASK_ALLOW_MISSING = Feature.ALLOW_MISSING_VALUES.getMask();
48+
@SuppressWarnings("deprecation")
49+
private final static int FEAT_MASK_ALLOW_SINGLE_QUOTES = Feature.ALLOW_SINGLE_QUOTES.getMask();
50+
@SuppressWarnings("deprecation")
51+
private final static int FEAT_MASK_ALLOW_UNQUOTED_NAMES = Feature.ALLOW_UNQUOTED_FIELD_NAMES.getMask();
4652

4753
// This is the main input-code lookup table, fetched eagerly
4854
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
@@ -1496,10 +1502,10 @@ protected final String parseEscapedName(int[] quads, int qlen, int currQuad, int
14961502
*/
14971503
protected String _handleOddName(int ch) throws IOException
14981504
{
1499-
if (ch == '\'' && isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
1505+
if (ch == '\'' && (_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) {
15001506
return _parseAposName();
15011507
}
1502-
if (!isEnabled(Feature.ALLOW_UNQUOTED_FIELD_NAMES)) {
1508+
if ((_features & FEAT_MASK_ALLOW_UNQUOTED_NAMES) == 0) {
15031509
char c = (char) _decodeCharForError(ch);
15041510
_reportUnexpectedChar(c, "was expecting double-quote to start field name");
15051511
}
@@ -2015,7 +2021,7 @@ protected JsonToken _handleUnexpectedValue(int c)
20152021
/* !!! TODO: 08-May-2016, tatu: To support `Feature.ALLOW_MISSING_VALUES` would
20162022
* need handling here...
20172023
*/
2018-
if (isEnabled(Feature.ALLOW_MISSING_VALUES)) {
2024+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
20192025
// _inputPtr--;
20202026
_nextByte = c;
20212027
return JsonToken.VALUE_NULL;
@@ -2026,7 +2032,7 @@ protected JsonToken _handleUnexpectedValue(int c)
20262032
// been handled earlier
20272033
_reportUnexpectedChar(c, "expected a value");
20282034
case '\'':
2029-
if (isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
2035+
if ((_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) {
20302036
return _handleApos();
20312037
}
20322038
break;

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public class UTF8StreamJsonParser
2626
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
2727
@SuppressWarnings("deprecation")
2828
private final static int FEAT_MASK_NON_NUM_NUMBERS = Feature.ALLOW_NON_NUMERIC_NUMBERS.getMask();
29+
@SuppressWarnings("deprecation")
30+
private final static int FEAT_MASK_ALLOW_MISSING = Feature.ALLOW_MISSING_VALUES.getMask();
31+
@SuppressWarnings("deprecation")
32+
private final static int FEAT_MASK_ALLOW_SINGLE_QUOTES = Feature.ALLOW_SINGLE_QUOTES.getMask();
33+
@SuppressWarnings("deprecation")
34+
private final static int FEAT_MASK_ALLOW_UNQUOTED_NAMES = Feature.ALLOW_UNQUOTED_FIELD_NAMES.getMask();
2935

3036
// This is the main input-code lookup table, fetched eagerly
3137
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
@@ -1984,11 +1990,11 @@ protected final String parseEscapedName(int[] quads, int qlen, int currQuad, int
19841990
protected String _handleOddName(int ch) throws IOException
19851991
{
19861992
// First: may allow single quotes
1987-
if (ch == INT_APOS && isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
1993+
if (ch == INT_APOS && (_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) {
19881994
return _parseAposName();
19891995
}
19901996
// Allow unquoted names if feature enabled:
1991-
if (!isEnabled(Feature.ALLOW_UNQUOTED_FIELD_NAMES)) {
1997+
if ((_features & FEAT_MASK_ALLOW_UNQUOTED_NAMES) == 0) {
19921998
char c = (char) _decodeCharForError(ch);
19931999
_reportUnexpectedChar(c, "was expecting double-quote to start field name");
19942000
}
@@ -2583,7 +2589,7 @@ protected JsonToken _handleUnexpectedValue(int c) throws IOException
25832589
// 28-Mar-2016: [core#116]: If Feature.ALLOW_MISSING_VALUES is enabled
25842590
// we may allow "missing values", that is, encountering a trailing
25852591
// comma or closing marker where value would be expected
2586-
if (isEnabled(Feature.ALLOW_MISSING_VALUES)) {
2592+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
25872593
--_inputPtr;
25882594
return JsonToken.VALUE_NULL;
25892595
}
@@ -2593,7 +2599,7 @@ protected JsonToken _handleUnexpectedValue(int c) throws IOException
25932599
// been handled earlier
25942600
_reportUnexpectedChar(c, "expected a value");
25952601
case '\'':
2596-
if (isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
2602+
if ((_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) {
25972603
return _handleApos();
25982604
}
25992605
break;

src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public class NonBlockingJsonParser
1919
private final static int FEAT_MASK_TRAILING_COMMA = Feature.ALLOW_TRAILING_COMMA.getMask();
2020
@SuppressWarnings("deprecation")
2121
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
22+
@SuppressWarnings("deprecation")
23+
private final static int FEAT_MASK_ALLOW_MISSING = Feature.ALLOW_MISSING_VALUES.getMask();
24+
@SuppressWarnings("deprecation")
25+
private final static int FEAT_MASK_ALLOW_SINGLE_QUOTES = Feature.ALLOW_SINGLE_QUOTES.getMask();
26+
@SuppressWarnings("deprecation")
27+
private final static int FEAT_MASK_ALLOW_UNQUOTED_NAMES = Feature.ALLOW_UNQUOTED_FIELD_NAMES.getMask();
2228

2329
// This is the main input-code lookup table, fetched eagerly
2430
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
@@ -890,7 +896,7 @@ protected JsonToken _startUnexpectedValue(boolean leadingComma, int ch) throws I
890896
// 28-Mar-2016: [core#116]: If Feature.ALLOW_MISSING_VALUES is enabled
891897
// we may allow "missing values", that is, encountering a trailing
892898
// comma or closing marker where value would be expected
893-
if (isEnabled(Feature.ALLOW_MISSING_VALUES)) {
899+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
894900
--_inputPtr;
895901
return _valueComplete(JsonToken.VALUE_NULL);
896902
}
@@ -900,7 +906,7 @@ protected JsonToken _startUnexpectedValue(boolean leadingComma, int ch) throws I
900906
// been handled earlier
901907
break;
902908
case '\'':
903-
if (isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
909+
if ((_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) {
904910
return _startAposString();
905911
}
906912
break;
@@ -2060,15 +2066,15 @@ private JsonToken _handleOddName(int ch) throws IOException
20602066
case '/':
20612067
return _startSlashComment(MINOR_FIELD_LEADING_WS);
20622068
case '\'':
2063-
if (isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
2069+
if ((_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) {
20642070
return _finishAposName(0, 0, 0);
20652071
}
20662072
break;
20672073
case ']': // for better error reporting...
20682074
return _closeArrayScope();
20692075
}
20702076
// allow unquoted names if feature enabled:
2071-
if (!isEnabled(Feature.ALLOW_UNQUOTED_FIELD_NAMES)) {
2077+
if ((_features & FEAT_MASK_ALLOW_UNQUOTED_NAMES) == 0) {
20722078
// !!! TODO: Decode UTF-8 characters properly...
20732079
// char c = (char) _decodeCharForError(ch);
20742080
char c = (char) ch;

src/test/java/com/fasterxml/jackson/core/json/async/AsyncFieldNamesTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
import com.fasterxml.jackson.core.*;
66
import com.fasterxml.jackson.core.async.AsyncTestBase;
7+
import com.fasterxml.jackson.core.json.JsonReadFeature;
78
import com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper;
89

910
public class AsyncFieldNamesTest extends AsyncTestBase
1011
{
1112
private final JsonFactory JSON_F = new JsonFactory();
1213

13-
private final JsonFactory JSON_APOS_F = new JsonFactory();
14-
{
15-
JSON_APOS_F.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
16-
}
14+
private final JsonFactory JSON_APOS_F = JsonFactory.builder()
15+
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
16+
.build();
1717

1818
// Mainly to test "fast" parse for shortish names
1919
public void testSimpleFieldNames() throws IOException

src/test/java/com/fasterxml/jackson/core/json/async/AsyncNonStdParsingTest.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public class AsyncNonStdParsingTest extends AsyncTestBase
1111
{
1212
public void testLargeUnquotedNames() throws Exception
1313
{
14-
JsonFactory f = new JsonFactory();
15-
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
16-
14+
final JsonFactory f = JsonFactory.builder()
15+
.enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES)
16+
.build();
1717
StringBuilder sb = new StringBuilder(5000);
1818
sb.append("[\n");
1919
final int REPS = 1050;
@@ -60,9 +60,9 @@ private void _testLargeUnquoted(JsonFactory f, int reps, String doc,
6060

6161
public void testSimpleUnquotedNames() throws Exception
6262
{
63-
final JsonFactory f = new JsonFactory();
64-
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
65-
63+
final JsonFactory f = JsonFactory.builder()
64+
.enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES)
65+
.build();
6666
_testSimpleUnquoted(f, 0, 99);
6767
_testSimpleUnquoted(f, 0, 5);
6868
_testSimpleUnquoted(f, 0, 3);
@@ -171,9 +171,9 @@ private void _testSingleQuotesDefault(JsonFactory f,
171171
*/
172172
public void testAposQuotingEnabled() throws Exception
173173
{
174-
JsonFactory f = new JsonFactory();
175-
f.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
176-
174+
final JsonFactory f = JsonFactory.builder()
175+
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
176+
.build();
177177
_testAposQuotingEnabled(f, 0, 99);
178178
_testAposQuotingEnabled(f, 0, 5);
179179
_testAposQuotingEnabled(f, 0, 3);
@@ -269,9 +269,9 @@ private void _testAposQuotingEnabled(JsonFactory f,
269269
// test to verify that we implicitly allow escaping of apostrophe
270270
public void testSingleQuotesEscaped() throws Exception
271271
{
272-
JsonFactory f = new JsonFactory();
273-
f.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
274-
272+
final JsonFactory f = JsonFactory.builder()
273+
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
274+
.build();
275275
_testSingleQuotesEscaped(f, 0, 99);
276276
_testSingleQuotesEscaped(f, 0, 5);
277277
_testSingleQuotesEscaped(f, 0, 3);
@@ -296,9 +296,9 @@ private void _testSingleQuotesEscaped(JsonFactory f,
296296

297297
public void testNonStandardNameChars() throws Exception
298298
{
299-
JsonFactory f = new JsonFactory();
300-
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
301-
299+
final JsonFactory f = JsonFactory.builder()
300+
.enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES)
301+
.build();
302302
_testNonStandardNameChars(f, 0, 99);
303303
_testNonStandardNameChars(f, 0, 6);
304304
_testNonStandardNameChars(f, 0, 3);

src/test/java/com/fasterxml/jackson/core/main/TestParserFeatures.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.*;
44

55
import com.fasterxml.jackson.core.*;
6+
import com.fasterxml.jackson.core.json.JsonReadFeature;
67

78
/**
89
* Unit tests for verifying that additional <code>JsonParser.Feature</code>
@@ -108,7 +109,7 @@ private void _testTabsDefault(boolean useStream) throws Exception
108109
private void _testTabsEnabled(boolean useStream) throws Exception
109110
{
110111
JsonFactory f = JsonFactory.builder()
111-
.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true)
112+
.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS, true)
112113
.build();
113114

114115
String FIELD = "a\tb";

0 commit comments

Comments
 (0)