Skip to content

Commit e9e2a62

Browse files
committed
Complete 2.10 initial version of #467
1 parent a2e846e commit e9e2a62

File tree

10 files changed

+72
-33
lines changed

10 files changed

+72
-33
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ public enum Feature {
7373
* this is extensively used. As such, feature is
7474
* <b>disabled by default</b> for parsers and must be
7575
* explicitly enabled.
76+
*
77+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_JAVA_COMMENTS} instead
7678
*/
79+
@Deprecated
7780
ALLOW_COMMENTS(false),
7881

7982
/**
@@ -87,7 +90,10 @@ public enum Feature {
8790
* this is a non-standard feature. As such, feature is
8891
* <b>disabled by default</b> for parsers and must be
8992
* explicitly enabled.
93+
*
94+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_YAML_COMMENTS} instead
9095
*/
96+
@Deprecated
9197
ALLOW_YAML_COMMENTS(false),
9298

9399
/**

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

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public enum JsonReadFeature
2424
* <b>disabled by default</b> for parsers and must be
2525
* explicitly enabled.
2626
*/
27+
@SuppressWarnings("deprecation")
2728
ALLOW_JAVA_COMMENTS(false, JsonParser.Feature.ALLOW_COMMENTS),
2829

2930
/**
@@ -38,6 +39,7 @@ public enum JsonReadFeature
3839
* <b>disabled by default</b> for parsers and must be
3940
* explicitly enabled.
4041
*/
42+
@SuppressWarnings("deprecation")
4143
ALLOW_YAML_COMMENTS(false, JsonParser.Feature.ALLOW_YAML_COMMENTS),
4244

4345
// // // Support for non-standard data format constructs: quoting/escaping

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class ReaderBasedJsonParser // final in 2.3, earlier
3535
@SuppressWarnings("deprecation")
3636
private final static int FEAT_MASK_ALLOW_UNQUOTED_NAMES = Feature.ALLOW_UNQUOTED_FIELD_NAMES.getMask();
3737

38+
@SuppressWarnings("deprecation")
39+
private final static int FEAT_MASK_ALLOW_JAVA_COMMENTS = Feature.ALLOW_COMMENTS.getMask();
40+
@SuppressWarnings("deprecation")
41+
private final static int FEAT_MASK_ALLOW_YAML_COMMENTS = Feature.ALLOW_YAML_COMMENTS.getMask();
42+
3843
// Latin1 encoding is not supported, but we do use 8-bit subset for
3944
// pre-processing task, to simplify first pass, keep it fast.
4045
protected final static int[] _icLatin1 = CharTypes.getInputCodeLatin1();
@@ -2424,7 +2429,7 @@ private int _skipWSOrEnd2() throws IOException
24242429

24252430
private void _skipComment() throws IOException
24262431
{
2427-
if (!isEnabled(Feature.ALLOW_COMMENTS)) {
2432+
if ((_features & FEAT_MASK_ALLOW_JAVA_COMMENTS) == 0) {
24282433
_reportUnexpectedChar('/', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)");
24292434
}
24302435
// First: check which comment (if either) it is:
@@ -2474,7 +2479,7 @@ private void _skipCComment() throws IOException
24742479

24752480
private boolean _skipYAMLComment() throws IOException
24762481
{
2477-
if (!isEnabled(Feature.ALLOW_YAML_COMMENTS)) {
2482+
if ((_features & FEAT_MASK_ALLOW_YAML_COMMENTS) == 0) {
24782483
return false;
24792484
}
24802485
_skipLine();

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public class UTF8DataInputJsonParser
4949
private final static int FEAT_MASK_ALLOW_SINGLE_QUOTES = Feature.ALLOW_SINGLE_QUOTES.getMask();
5050
@SuppressWarnings("deprecation")
5151
private final static int FEAT_MASK_ALLOW_UNQUOTED_NAMES = Feature.ALLOW_UNQUOTED_FIELD_NAMES.getMask();
52+
@SuppressWarnings("deprecation")
53+
private final static int FEAT_MASK_ALLOW_JAVA_COMMENTS = Feature.ALLOW_COMMENTS.getMask();
54+
@SuppressWarnings("deprecation")
55+
private final static int FEAT_MASK_ALLOW_YAML_COMMENTS = Feature.ALLOW_YAML_COMMENTS.getMask();
5256

5357
// This is the main input-code lookup table, fetched eagerly
5458
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
@@ -2371,7 +2375,7 @@ private final int _skipColon2(int i, boolean gotColon) throws IOException
23712375

23722376
private final void _skipComment() throws IOException
23732377
{
2374-
if (!isEnabled(Feature.ALLOW_COMMENTS)) {
2378+
if ((_features & FEAT_MASK_ALLOW_JAVA_COMMENTS) == 0) {
23752379
_reportUnexpectedChar('/', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)");
23762380
}
23772381
int c = _inputData.readUnsignedByte();
@@ -2426,7 +2430,7 @@ private final void _skipCComment() throws IOException
24262430

24272431
private final boolean _skipYAMLComment() throws IOException
24282432
{
2429-
if (!isEnabled(Feature.ALLOW_YAML_COMMENTS)) {
2433+
if ((_features & FEAT_MASK_ALLOW_YAML_COMMENTS) == 0) {
24302434
return false;
24312435
}
24322436
_skipLine();

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class UTF8StreamJsonParser
3232
private final static int FEAT_MASK_ALLOW_SINGLE_QUOTES = Feature.ALLOW_SINGLE_QUOTES.getMask();
3333
@SuppressWarnings("deprecation")
3434
private final static int FEAT_MASK_ALLOW_UNQUOTED_NAMES = Feature.ALLOW_UNQUOTED_FIELD_NAMES.getMask();
35+
@SuppressWarnings("deprecation")
36+
private final static int FEAT_MASK_ALLOW_JAVA_COMMENTS = Feature.ALLOW_COMMENTS.getMask();
37+
@SuppressWarnings("deprecation")
38+
private final static int FEAT_MASK_ALLOW_YAML_COMMENTS = Feature.ALLOW_YAML_COMMENTS.getMask();
3539

3640
// This is the main input-code lookup table, fetched eagerly
3741
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
@@ -3103,7 +3107,7 @@ private final int _skipColon2(boolean gotColon) throws IOException
31033107

31043108
private final void _skipComment() throws IOException
31053109
{
3106-
if (!isEnabled(Feature.ALLOW_COMMENTS)) {
3110+
if ((_features & FEAT_MASK_ALLOW_JAVA_COMMENTS) == 0) {
31073111
_reportUnexpectedChar('/', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)");
31083112
}
31093113
// First: check which comment (if either) it is:
@@ -3168,7 +3172,7 @@ private final void _skipCComment() throws IOException
31683172

31693173
private final boolean _skipYAMLComment() throws IOException
31703174
{
3171-
if (!isEnabled(Feature.ALLOW_YAML_COMMENTS)) {
3175+
if ((_features & FEAT_MASK_ALLOW_YAML_COMMENTS) == 0) {
31723176
return false;
31733177
}
31743178
_skipLine();

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class NonBlockingJsonParser
2525
private final static int FEAT_MASK_ALLOW_SINGLE_QUOTES = Feature.ALLOW_SINGLE_QUOTES.getMask();
2626
@SuppressWarnings("deprecation")
2727
private final static int FEAT_MASK_ALLOW_UNQUOTED_NAMES = Feature.ALLOW_UNQUOTED_FIELD_NAMES.getMask();
28+
@SuppressWarnings("deprecation")
29+
private final static int FEAT_MASK_ALLOW_JAVA_COMMENTS = Feature.ALLOW_COMMENTS.getMask();
30+
@SuppressWarnings("deprecation")
31+
private final static int FEAT_MASK_ALLOW_YAML_COMMENTS = Feature.ALLOW_YAML_COMMENTS.getMask();
2832

2933
// This is the main input-code lookup table, fetched eagerly
3034
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
@@ -953,7 +957,7 @@ private final int _skipWS(int ch) throws IOException
953957

954958
private final JsonToken _startSlashComment(int fromMinorState) throws IOException
955959
{
956-
if (!JsonParser.Feature.ALLOW_COMMENTS.enabledIn(_features)) {
960+
if ((_features & FEAT_MASK_ALLOW_JAVA_COMMENTS) == 0) {
957961
_reportUnexpectedChar('/', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)");
958962
}
959963

@@ -977,7 +981,7 @@ private final JsonToken _startSlashComment(int fromMinorState) throws IOExceptio
977981
private final JsonToken _finishHashComment(int fromMinorState) throws IOException
978982
{
979983
// Could by-pass this check by refactoring, but for now simplest way...
980-
if (!JsonParser.Feature.ALLOW_YAML_COMMENTS.enabledIn(_features)) {
984+
if ((_features & FEAT_MASK_ALLOW_YAML_COMMENTS) == 0) {
981985
_reportUnexpectedChar('#', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_YAML_COMMENTS' not enabled for parser)");
982986
}
983987
while (true) {
@@ -2059,7 +2063,7 @@ private JsonToken _handleOddName(int ch) throws IOException
20592063
case '#':
20602064
// Careful, since this may alternatively be leading char of
20612065
// unquoted name...
2062-
if (JsonParser.Feature.ALLOW_YAML_COMMENTS.enabledIn(_features)) {
2066+
if ((_features & FEAT_MASK_ALLOW_YAML_COMMENTS) != 0) {
20632067
return _finishHashComment(MINOR_FIELD_LEADING_WS);
20642068
}
20652069
break;

src/test/java/com/fasterxml/jackson/core/json/JsonFactoryTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public void testJsonWithFiles() throws Exception
193193
}
194194

195195
// #72
196+
@SuppressWarnings("deprecation")
196197
public void testCopy() throws Exception
197198
{
198199
JsonFactory jf = new JsonFactory();

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

+13-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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
/**
@@ -56,9 +57,9 @@ public void testCCommentsWithUTF8() throws Exception
5657

5758
public void testYAMLCommentsEnabled() throws Exception
5859
{
59-
JsonFactory f = new JsonFactory();
60-
f.enable(JsonParser.Feature.ALLOW_YAML_COMMENTS);
61-
60+
final JsonFactory f = JsonFactory.builder()
61+
.enable(JsonReadFeature.ALLOW_YAML_COMMENTS)
62+
.build();
6263
_testYAMLComments(f, 99);
6364
_testYAMLComments(f, 3);
6465
_testYAMLComments(f, 1);
@@ -73,17 +74,19 @@ public void testYAMLCommentsEnabled() throws Exception
7374
}
7475

7576
public void testCCommentsEnabled() throws Exception {
76-
JsonFactory f = new JsonFactory();
77-
f.enable(JsonParser.Feature.ALLOW_COMMENTS);
77+
final JsonFactory f = JsonFactory.builder()
78+
.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)
79+
.build();
7880
final String COMMENT = "/* foo */\n";
7981
_testCommentsBeforePropValue(f, COMMENT, 99);
8082
_testCommentsBeforePropValue(f, COMMENT, 3);
8183
_testCommentsBeforePropValue(f, COMMENT, 1);
8284
}
8385

8486
public void testCppCommentsEnabled() throws Exception {
85-
JsonFactory f = new JsonFactory();
86-
f.enable(JsonParser.Feature.ALLOW_COMMENTS);
87+
final JsonFactory f = JsonFactory.builder()
88+
.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)
89+
.build();
8790
final String COMMENT = "// foo\n";
8891
_testCommentsBeforePropValue(f, COMMENT, 99);
8992
_testCommentsBeforePropValue(f, COMMENT, 3);
@@ -241,8 +244,9 @@ private AsyncReaderWrapper _createParser(String doc, boolean enabled,
241244
int bytesPerRead)
242245
throws IOException
243246
{
244-
JsonFactory f = new JsonFactory();
245-
f.configure(JsonParser.Feature.ALLOW_COMMENTS, enabled);
247+
final JsonFactory f = JsonFactory.builder()
248+
.configure(JsonReadFeature.ALLOW_JAVA_COMMENTS, enabled)
249+
.build();
246250
return asyncForBytes(f, bytesPerRead, _jsonDoc(doc), 0);
247251
}
248252

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public void testDefaultSettings() throws Exception
1616
{
1717
JsonFactory f = new JsonFactory();
1818
assertTrue(f.isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
19-
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
2019

2120
JsonParser p = f.createParser(new StringReader("{}"));
2221
_testDefaultSettings(p);
@@ -30,6 +29,7 @@ public void testDefaultSettings() throws Exception
3029
public void testDeprecatedDefaultSettings() throws Exception
3130
{
3231
JsonFactory f = new JsonFactory();
32+
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
3333
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS));
3434
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES));
3535
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_SINGLE_QUOTES));

src/test/java/com/fasterxml/jackson/core/read/CommentParsingTest.java

+23-14
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 support for (non-standard) comments
@@ -29,6 +30,7 @@ public class CommentParsingTest
2930
* Unit test for verifying that by default comments are not
3031
* recognized.
3132
*/
33+
@SuppressWarnings("deprecation")
3234
public void testDefaultSettings() throws Exception
3335
{
3436
JsonFactory jf = new JsonFactory();
@@ -72,8 +74,9 @@ public void testCommentsWithUTF8() throws Exception
7274
}
7375

7476
public void testYAMLCommentsBytes() throws Exception {
75-
JsonFactory f = new JsonFactory();
76-
f.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
77+
final JsonFactory f = JsonFactory.builder()
78+
.enable(JsonReadFeature.ALLOW_YAML_COMMENTS)
79+
.build();
7780

7881
_testYAMLComments(f, MODE_INPUT_STREAM);
7982
_testCommentsBeforePropValue(f, MODE_INPUT_STREAM, "# foo\n");
@@ -84,42 +87,47 @@ public void testYAMLCommentsBytes() throws Exception {
8487
}
8588

8689
public void testYAMLCommentsChars() throws Exception {
87-
JsonFactory f = new JsonFactory();
88-
f.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
90+
final JsonFactory f = JsonFactory.builder()
91+
.enable(JsonReadFeature.ALLOW_YAML_COMMENTS)
92+
.build();
8993
_testYAMLComments(f, MODE_READER);
9094
final String COMMENT = "# foo\n";
9195
_testCommentsBeforePropValue(f, MODE_READER, COMMENT);
9296
_testCommentsBetweenArrayValues(f, MODE_READER, COMMENT);
9397
}
9498

9599
public void testCCommentsBytes() throws Exception {
96-
JsonFactory f = new JsonFactory();
97-
f.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
100+
final JsonFactory f = JsonFactory.builder()
101+
.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)
102+
.build();
98103
final String COMMENT = "/* foo */\n";
99104
_testCommentsBeforePropValue(f, MODE_INPUT_STREAM, COMMENT);
100105
_testCommentsBeforePropValue(f, MODE_INPUT_STREAM_THROTTLED, COMMENT);
101106
_testCommentsBeforePropValue(f, MODE_DATA_INPUT, COMMENT);
102107
}
103108

104109
public void testCCommentsChars() throws Exception {
105-
JsonFactory f = new JsonFactory();
106-
f.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
110+
final JsonFactory f = JsonFactory.builder()
111+
.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)
112+
.build();
107113
final String COMMENT = "/* foo */\n";
108114
_testCommentsBeforePropValue(f, MODE_READER, COMMENT);
109115
}
110116

111117
public void testCppCommentsBytes() throws Exception {
112-
JsonFactory f = new JsonFactory();
113-
f.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
118+
final JsonFactory f = JsonFactory.builder()
119+
.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)
120+
.build();
114121
final String COMMENT = "// foo\n";
115122
_testCommentsBeforePropValue(f, MODE_INPUT_STREAM, COMMENT);
116123
_testCommentsBeforePropValue(f, MODE_INPUT_STREAM_THROTTLED, COMMENT);
117124
_testCommentsBeforePropValue(f, MODE_DATA_INPUT, COMMENT);
118125
}
119126

120127
public void testCppCommentsChars() throws Exception {
121-
JsonFactory f = new JsonFactory();
122-
f.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
128+
final JsonFactory f = JsonFactory.builder()
129+
.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)
130+
.build();
123131
final String COMMENT = "// foo \n";
124132
_testCommentsBeforePropValue(f, MODE_READER, COMMENT);
125133
}
@@ -277,8 +285,9 @@ private void _testEnabled(String doc, int mode) throws IOException
277285
private JsonParser _createParser(String doc, int mode, boolean enabled)
278286
throws IOException
279287
{
280-
JsonFactory f = new JsonFactory();
281-
f.configure(JsonParser.Feature.ALLOW_COMMENTS, enabled);
288+
final JsonFactory f = JsonFactory.builder()
289+
.configure(JsonReadFeature.ALLOW_JAVA_COMMENTS, enabled)
290+
.build();
282291
JsonParser p = createParser(f, mode, doc);
283292
assertToken(JsonToken.START_ARRAY, p.nextToken());
284293
return p;

0 commit comments

Comments
 (0)