Skip to content

Commit ab01132

Browse files
committed
Continue work on #467
1 parent ee1e08e commit ab01132

13 files changed

+121
-88
lines changed

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

-8
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,15 @@ public class JsonFactoryBuilder extends TSFBuilder<JsonFactory, JsonFactoryBuild
1717

1818
protected SerializableString _rootValueSeparator;
1919

20-
protected boolean _handleBSONWrappers;
21-
2220
public JsonFactoryBuilder() {
2321
super();
2422
_rootValueSeparator = JsonFactory.DEFAULT_ROOT_VALUE_SEPARATOR;
25-
_handleBSONWrappers = JsonReadFeature.HANDLE_BSON_WRAPPERS.enabledByDefault();
2623
}
2724

2825
public JsonFactoryBuilder(JsonFactory base) {
2926
super(base);
3027
_characterEscapes = base.getCharacterEscapes();
3128
_rootValueSeparator = base._rootValueSeparator;
32-
// _handleBSONWrappers = base._handleBSONWrappers;
3329
}
3430

3531
/*
@@ -45,8 +41,6 @@ public JsonFactoryBuilder enable(JsonReadFeature f) {
4541
JsonParser.Feature old = f.mappedFeature();
4642
if (old != null) {
4743
enable(old);
48-
} else if (f == JsonReadFeature.HANDLE_BSON_WRAPPERS) {
49-
_handleBSONWrappers = true;
5044
}
5145
return _this();
5246
}
@@ -65,8 +59,6 @@ public JsonFactoryBuilder disable(JsonReadFeature f) {
6559
JsonParser.Feature old = f.mappedFeature();
6660
if (old != null) {
6761
disable(old);
68-
} else if (f == JsonReadFeature.HANDLE_BSON_WRAPPERS) {
69-
_handleBSONWrappers = false;
7062
}
7163
return _this();
7264
}

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ public enum Feature {
147147
*<p>
148148
* Since JSON specification does not allow leading zeroes,
149149
* this is a non-standard feature, and as such disabled by default.
150-
*/
150+
*
151+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_LEADING_ZEROS_FOR_NUMBERS} instead
152+
*/
153+
@Deprecated
151154
ALLOW_NUMERIC_LEADING_ZEROS(false),
152155

153156
/**
@@ -167,7 +170,10 @@ public enum Feature {
167170
*<p>
168171
* Since JSON specification does not allow use of such values,
169172
* this is a non-standard feature, and as such disabled by default.
170-
*/
173+
*
174+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_NON_NUMERIC_NUMBERS} instead
175+
*/
176+
@Deprecated
171177
ALLOW_NON_NUMERIC_NUMBERS(false),
172178

173179
/**
@@ -186,8 +192,9 @@ public enum Feature {
186192
*
187193
* @since 2.8
188194
*
189-
* @deprecated Since 2.10 use {@link JsonReadFeature#ALLOW_MISSING_VALUES} instead
195+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_MISSING_VALUES} instead
190196
*/
197+
@Deprecated
191198
ALLOW_MISSING_VALUES(false),
192199

193200
/**
@@ -211,8 +218,9 @@ public enum Feature {
211218
*
212219
* @since 2.9
213220
*
214-
* @deprecated Since 2.10 use {@link JsonReadFeature#ALLOW_TRAILING_COMMA} instead
221+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_TRAILING_COMMA} instead
215222
*/
223+
@Deprecated
216224
ALLOW_TRAILING_COMMA(false),
217225

218226
// // // Validity checks

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

+2-15
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public enum JsonReadFeature
102102
* Since JSON specification does not allow leading zeroes,
103103
* this is a non-standard feature, and as such disabled by default.
104104
*/
105+
@SuppressWarnings("deprecation")
105106
ALLOW_LEADING_ZEROS_FOR_NUMBERS(false, JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS),
106107

107108
/**
@@ -122,6 +123,7 @@ public enum JsonReadFeature
122123
* Since JSON specification does not allow use of such values,
123124
* this is a non-standard feature, and as such disabled by default.
124125
*/
126+
@SuppressWarnings("deprecation")
125127
ALLOW_NON_NUMERIC_NUMBERS(false, JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS),
126128

127129
// // // Support for non-standard data format constructs: array/value separators
@@ -164,21 +166,6 @@ public enum JsonReadFeature
164166
*/
165167
@SuppressWarnings("deprecation")
166168
ALLOW_TRAILING_COMMA(false, JsonParser.Feature.ALLOW_TRAILING_COMMA),
167-
168-
// // // Support for non-standard data format constructs: JSON-like formats
169-
170-
/**
171-
* Feature that can be turned on to support handling of BSON "shell mode" JSON extensions
172-
* as specified <a href="https://docs.mongodb.com/manual/reference/mongodb-extended-json/">here</a>
173-
* for "shell mode" (but NOT "strict mode" which uses standard JSON syntax but additional
174-
* structural constructs).
175-
*<p>
176-
* NOTE: although attempt is made to support various extension wrappers there is no guarantee that
177-
* all semantic aspects are retained for higher level processing.
178-
*
179-
* @since 2.10
180-
*/
181-
HANDLE_BSON_WRAPPERS(false, null)
182169
;
183170

184171
final private boolean _defaultState;

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
public class ReaderBasedJsonParser // final in 2.3, earlier
2020
extends ParserBase
2121
{
22-
protected final static int FEAT_MASK_TRAILING_COMMA = Feature.ALLOW_TRAILING_COMMA.getMask();
22+
@SuppressWarnings("deprecation")
23+
private final static int FEAT_MASK_TRAILING_COMMA = Feature.ALLOW_TRAILING_COMMA.getMask();
24+
25+
@SuppressWarnings("deprecation")
26+
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
2327

2428
// Latin1 encoding is not supported, but we do use 8-bit subset for
2529
// pre-processing task, to simplify first pass, keep it fast.
@@ -1117,14 +1121,13 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
11171121
*/
11181122
case ',':
11191123
case ']':
1120-
if(isEnabled(Feature.ALLOW_MISSING_VALUES)) {
1121-
_inputPtr--;
1122-
return (_currToken = JsonToken.VALUE_NULL);
1123-
}
1124+
if (isEnabled(Feature.ALLOW_MISSING_VALUES)) {
1125+
--_inputPtr;
1126+
return (_currToken = JsonToken.VALUE_NULL);
1127+
}
11241128
}
11251129
return (_currToken = _handleOddValue(i));
11261130
}
1127-
11281131
// note: identical to one in UTF8StreamJsonParser
11291132
@Override
11301133
public final String nextTextValue() throws IOException
@@ -1577,7 +1580,7 @@ private char _verifyNLZ2() throws IOException
15771580
if (ch < '0' || ch > '9') {
15781581
return '0';
15791582
}
1580-
if (!isEnabled(Feature.ALLOW_NUMERIC_LEADING_ZEROS)) {
1583+
if ((_features & FEAT_MASK_LEADING_ZEROS) == 0) {
15811584
reportInvalidNumber("Leading zeroes not allowed");
15821585
}
15831586
// if so, just need to skip either all zeroes (if followed by number); or all but one (if non-number)

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public class UTF8DataInputJsonParser
3737
{
3838
final static byte BYTE_LF = (byte) '\n';
3939

40+
@SuppressWarnings("deprecation")
41+
private final static int FEAT_MASK_TRAILING_COMMA = Feature.ALLOW_TRAILING_COMMA.getMask();
42+
@SuppressWarnings("deprecation")
43+
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
44+
4045
// This is the main input-code lookup table, fetched eagerly
4146
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
4247

@@ -599,7 +604,7 @@ public JsonToken nextToken() throws IOException
599604
i = _skipWS();
600605

601606
// Was that a trailing comma?
602-
if (Feature.ALLOW_TRAILING_COMMA.enabledIn(_features)) {
607+
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
603608
if (i == INT_RBRACKET || i == INT_RCURLY) {
604609
_closeScope(i);
605610
return _currToken;
@@ -781,7 +786,7 @@ public String nextFieldName() throws IOException
781786
i = _skipWS();
782787

783788
// Was that a trailing comma?
784-
if (Feature.ALLOW_TRAILING_COMMA.enabledIn(_features)) {
789+
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
785790
if (i == INT_RBRACKET || i == INT_RCURLY) {
786791
_closeScope(i);
787792
return null;
@@ -1073,7 +1078,7 @@ private final int _handleLeadingZeroes() throws IOException
10731078
return ch;
10741079
}
10751080
// we may want to allow leading zeroes them, after all...
1076-
if (!isEnabled(Feature.ALLOW_NUMERIC_LEADING_ZEROS)) {
1081+
if ((_features & FEAT_MASK_LEADING_ZEROS) == 0) {
10771082
reportInvalidNumber("Leading zeroes not allowed");
10781083
}
10791084
// if so, just need to skip either all zeroes (if followed by number); or all but one (if non-number)

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ public class UTF8StreamJsonParser
2020
{
2121
final static byte BYTE_LF = (byte) '\n';
2222

23+
@SuppressWarnings("deprecation")
24+
private final static int FEAT_MASK_TRAILING_COMMA = Feature.ALLOW_TRAILING_COMMA.getMask();
25+
@SuppressWarnings("deprecation")
26+
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
27+
2328
// This is the main input-code lookup table, fetched eagerly
2429
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
2530

2631
// Latin1 encoding is not supported, but we do use 8-bit subset for
2732
// pre-processing task, to simplify first pass, keep it fast.
2833
protected final static int[] _icLatin1 = CharTypes.getInputCodeLatin1();
2934

30-
protected final static int FEAT_MASK_TRAILING_COMMA = Feature.ALLOW_TRAILING_COMMA.getMask();
31-
3235
/*
3336
/**********************************************************
3437
/* Configuration
@@ -1483,7 +1486,7 @@ private final int _verifyNoLeadingZeroes() throws IOException
14831486
return INT_0;
14841487
}
14851488
// [JACKSON-358]: we may want to allow them, after all...
1486-
if (!isEnabled(Feature.ALLOW_NUMERIC_LEADING_ZEROS)) {
1489+
if ((_features & FEAT_MASK_LEADING_ZEROS) == 0) {
14871490
reportInvalidNumber("Leading zeroes not allowed");
14881491
}
14891492
// if so, just need to skip either all zeroes (if followed by number); or all but one (if non-number)

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public class NonBlockingJsonParser
1515
extends NonBlockingJsonParserBase
1616
implements ByteArrayFeeder
1717
{
18+
@SuppressWarnings("deprecation")
19+
private final static int FEAT_MASK_TRAILING_COMMA = Feature.ALLOW_TRAILING_COMMA.getMask();
20+
@SuppressWarnings("deprecation")
21+
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
22+
1823
// This is the main input-code lookup table, fetched eagerly
1924
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
2025

@@ -552,7 +557,7 @@ private final JsonToken _startFieldNameAfterComma(int ch) throws IOException
552557
_updateTokenLocation();
553558
if (ch != INT_QUOTE) {
554559
if (ch == INT_RCURLY) {
555-
if (JsonParser.Feature.ALLOW_TRAILING_COMMA.enabledIn(_features)) {
560+
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
556561
return _closeObjectScope();
557562
}
558563
}
@@ -712,15 +717,15 @@ private final JsonToken _startValueExpectComma(int ch) throws IOException
712717
return _startArrayScope();
713718
case ']':
714719
// Was that a trailing comma?
715-
if (isEnabled(Feature.ALLOW_TRAILING_COMMA)) {
720+
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
716721
return _closeArrayScope();
717722
}
718723
break;
719724
case '{':
720725
return _startObjectScope();
721726
case '}':
722727
// Was that a trailing comma?
723-
if (isEnabled(Feature.ALLOW_TRAILING_COMMA)) {
728+
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
724729
return _closeObjectScope();
725730
}
726731
break;
@@ -856,15 +861,15 @@ private final JsonToken _startValueAfterComma(int ch) throws IOException
856861
return _startArrayScope();
857862
case ']':
858863
// Was that a trailing comma?
859-
if (isEnabled(Feature.ALLOW_TRAILING_COMMA)) {
864+
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
860865
return _closeArrayScope();
861866
}
862867
break;
863868
case '{':
864869
return _startObjectScope();
865870
case '}':
866871
// Was that a trailing comma?
867-
if (isEnabled(Feature.ALLOW_TRAILING_COMMA)) {
872+
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
868873
return _closeObjectScope();
869874
}
870875
break;
@@ -1476,7 +1481,7 @@ protected JsonToken _finishNumberLeadingZeroes() throws IOException
14761481
} else { // Number between 0 and 9
14771482
// although not guaranteed, seems likely valid separator (white space,
14781483
// comma, end bracket/curly); next time token needed will verify
1479-
if (!isEnabled(Feature.ALLOW_NUMERIC_LEADING_ZEROS)) {
1484+
if ((_features & FEAT_MASK_LEADING_ZEROS) == 0) {
14801485
reportInvalidNumber("Leading zeroes not allowed");
14811486
}
14821487
if (ch == INT_0) { // coalesce multiple leading zeroes into just one
@@ -1529,7 +1534,7 @@ protected JsonToken _finishNumberLeadingNegZeroes() throws IOException
15291534
} else { // Number between 1 and 9; go integral
15301535
// although not guaranteed, seems likely valid separator (white space,
15311536
// comma, end bracket/curly); next time token needed will verify
1532-
if (!isEnabled(Feature.ALLOW_NUMERIC_LEADING_ZEROS)) {
1537+
if ((_features & FEAT_MASK_LEADING_ZEROS) == 0) {
15331538
reportInvalidNumber("Leading zeroes not allowed");
15341539
}
15351540
if (ch == INT_0) { // coalesce multiple leading zeroes into just one

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

+18-10
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
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 AsyncNonStdNumbersTest extends AsyncTestBase
1011
{
1112
private final JsonFactory DEFAULT_F = new JsonFactory();
1213

14+
@SuppressWarnings("deprecation")
15+
public void testDefaultsForAsync() throws Exception {
16+
assertFalse(DEFAULT_F.isEnabled(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS));
17+
}
18+
1319
public void testDisallowNaN() throws Exception
1420
{
1521
final String JSON = "[ NaN]";
16-
assertFalse(DEFAULT_F.isEnabled(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS));
1722

1823
// without enabling, should get an exception
1924
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
@@ -31,9 +36,9 @@ public void testDisallowNaN() throws Exception
3136
public void testAllowNaN() throws Exception
3237
{
3338
final String JSON = "[ NaN]";
34-
JsonFactory f = new JsonFactory();
35-
f.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
36-
39+
JsonFactory f = JsonFactory.builder()
40+
.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS)
41+
.build();
3742
_testAllowNaN(f, JSON, 99);
3843
_testAllowNaN(f, JSON, 5);
3944
_testAllowNaN(f, JSON, 3);
@@ -62,7 +67,9 @@ private void _testAllowNaN(JsonFactory f, String doc, int readBytes) throws Exce
6267
p.close();
6368

6469
// finally, should also work with skipping
65-
f.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
70+
f = JsonFactory.builder()
71+
.configure(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS, true)
72+
.build();
6673
p = createParser(f, doc, readBytes);
6774
assertToken(JsonToken.START_ARRAY, p.nextToken());
6875
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
@@ -91,7 +98,6 @@ public void testDisallowInf() throws Exception
9198

9299
private void _testDisallowInf(JsonFactory f, String token, int readBytes) throws Exception
93100
{
94-
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS));
95101
final String JSON = String.format("[%s]", token);
96102

97103
// without enabling, should get an exception
@@ -109,9 +115,9 @@ private void _testDisallowInf(JsonFactory f, String token, int readBytes) throws
109115

110116
public void testAllowInf() throws Exception
111117
{
112-
JsonFactory f = new JsonFactory();
113-
f.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
114-
118+
JsonFactory f = JsonFactory.builder()
119+
.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS)
120+
.build();
115121
String JSON = "[ Infinity, +Infinity, -Infinity ]";
116122
_testAllowInf(f, JSON, 99);
117123
_testAllowInf(f, JSON, 5);
@@ -160,7 +166,9 @@ private void _testAllowInf(JsonFactory f, String doc, int readBytes) throws Exce
160166
p.close();
161167

162168
// finally, should also work with skipping
163-
f.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
169+
f = JsonFactory.builder()
170+
.configure(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS, true)
171+
.build();
164172
p = createParser(f, doc, readBytes);
165173

166174
assertToken(JsonToken.START_ARRAY, p.nextToken());

0 commit comments

Comments
 (0)