Skip to content

Commit 9104ff8

Browse files
committed
Start work on #481 (JsonWriteFeature)
1 parent 65e6540 commit 9104ff8

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ JSON library.
1919
#467: Create `JsonReadFeature` to move JSON-specific `JsonParser.Feature`s to
2020
#480: `SerializableString` value can not directly render to Writer
2121
(requested by Philippe M)
22+
#481: Create `JsonWriteFeature` to move JSON-specific `JsonGenerator.Feature`s to
2223
#484: Implement `UTF8JsonGenerator.writeRawValue(SerializableString)` (and
2324
`writeRaw(..)`) more efficiently
2425

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ public enum Feature {
8585
* occurs when used straight from Javascript.
8686
*<p>
8787
* Feature is enabled by default (since it is required by JSON specification).
88+
*
89+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonWriteFeature#QUOTE_FIELD_NAMES} instead
8890
*/
89-
// @Deprecated
91+
@Deprecated
9092
QUOTE_FIELD_NAMES(true),
9193

9294
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public abstract class JsonGeneratorImpl extends GeneratorBase
9898
/**********************************************************
9999
*/
100100

101+
@SuppressWarnings("deprecation")
101102
public JsonGeneratorImpl(IOContext ctxt, int features, ObjectCodec codec)
102103
{
103104
super(features, codec);
@@ -126,6 +127,7 @@ public Version version() {
126127
/**********************************************************
127128
*/
128129

130+
@SuppressWarnings("deprecation")
129131
@Override
130132
public JsonGenerator enable(Feature f) {
131133
super.enable(f);
@@ -135,6 +137,7 @@ public JsonGenerator enable(Feature f) {
135137
return this;
136138
}
137139

140+
@SuppressWarnings("deprecation")
138141
@Override
139142
public JsonGenerator disable(Feature f) {
140143
super.disable(f);
@@ -144,6 +147,7 @@ public JsonGenerator disable(Feature f) {
144147
return this;
145148
}
146149

150+
@SuppressWarnings("deprecation")
147151
@Override
148152
protected void _checkStdFeatureChanges(int newFeatureFlags, int changedFeatures) {
149153
super._checkStdFeatureChanges(newFeatureFlags, changedFeatures);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public enum JsonWriteFeature
2323
*<p>
2424
* Feature is enabled by default (since it is required by JSON specification).
2525
*/
26+
@SuppressWarnings("deprecation")
2627
QUOTE_FIELD_NAMES(true, JsonGenerator.Feature.QUOTE_FIELD_NAMES),
2728

2829
/**

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ public void testFieldNameQuoting() throws IOException
5454
// by default, quoting should be enabled
5555
_testFieldNameQuoting(f, true);
5656
// can disable it
57-
f.disable(JsonGenerator.Feature.QUOTE_FIELD_NAMES);
57+
f = JsonFactory.builder()
58+
.disable(JsonWriteFeature.QUOTE_FIELD_NAMES)
59+
.build();
5860
_testFieldNameQuoting(f, false);
5961
// and (re)enable:
60-
f.enable(JsonGenerator.Feature.QUOTE_FIELD_NAMES);
62+
f = JsonFactory.builder()
63+
.enable(JsonWriteFeature.QUOTE_FIELD_NAMES)
64+
.build();
6165
_testFieldNameQuoting(f, true);
6266
}
6367

@@ -221,8 +225,9 @@ public void testFieldNameQuotingEnabled() throws IOException
221225

222226
// // Then with alternatively configured factory
223227

224-
JsonFactory f2 = new JsonFactory();
225-
f2.disable(JsonGenerator.Feature.QUOTE_FIELD_NAMES);
228+
JsonFactory f2 = JsonFactory.builder()
229+
.disable(JsonWriteFeature.QUOTE_FIELD_NAMES)
230+
.build();
226231

227232
_testFieldNameQuotingEnabled(f2, true, true, "{\"foo\":1}");
228233
_testFieldNameQuotingEnabled(f2, false, true, "{\"foo\":1}");
@@ -232,6 +237,7 @@ public void testFieldNameQuotingEnabled() throws IOException
232237
_testFieldNameQuotingEnabled(f2, false, false, "{foo:1}");
233238
}
234239

240+
@SuppressWarnings("deprecation")
235241
private void _testFieldNameQuotingEnabled(JsonFactory f, boolean useBytes,
236242
boolean useQuotes, String exp) throws IOException
237243
{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,20 @@ public CustomFactory(JsonFactory f, ObjectCodec codec) {
9292
/**********************************************************************
9393
*/
9494

95+
@SuppressWarnings("deprecation")
9596
public void testGeneratorFeatures() throws Exception
9697
{
9798
JsonFactory f = new JsonFactory();
9899
assertNull(f.getCodec());
99100

100-
f.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
101+
f = JsonFactory.builder()
102+
.configure(JsonWriteFeature.QUOTE_FIELD_NAMES, true)
103+
.build();
104+
// 24-Oct-2018, tatu: Until 3.x, we'll only have backwards compatible
101105
assertTrue(f.isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
102-
f.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false);
106+
f = JsonFactory.builder()
107+
.configure(JsonWriteFeature.QUOTE_FIELD_NAMES, false)
108+
.build();
103109
assertFalse(f.isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
104110
}
105111

0 commit comments

Comments
 (0)