Skip to content

Commit eeeb51e

Browse files
committed
work on support for JsonWriterFeature
1 parent 6cfdce3 commit eeeb51e

File tree

4 files changed

+74
-13
lines changed

4 files changed

+74
-13
lines changed

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

+46
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.core.io.CharacterEscapes;
44
import com.fasterxml.jackson.core.io.SerializedString;
55
import com.fasterxml.jackson.core.json.JsonReadFeature;
6+
import com.fasterxml.jackson.core.json.JsonWriteFeature;
67

78
/**
89
* {@link com.fasterxml.jackson.core.TSFBuilder}
@@ -77,6 +78,51 @@ public JsonFactoryBuilder configure(JsonReadFeature f, boolean state) {
7778
return state ? enable(f) : disable(f);
7879
}
7980

81+
// // // JSON-generating features
82+
83+
@Override
84+
public JsonFactoryBuilder enable(JsonWriteFeature f) {
85+
JsonGenerator.Feature old = f.mappedFeature();
86+
if (old != null) {
87+
enable(old);
88+
}
89+
return _this();
90+
}
91+
92+
@Override
93+
public JsonFactoryBuilder enable(JsonWriteFeature first, JsonWriteFeature... other) {
94+
enable(first);
95+
for (JsonWriteFeature f : other) {
96+
enable(f);
97+
}
98+
return _this();
99+
}
100+
101+
@Override
102+
public JsonFactoryBuilder disable(JsonWriteFeature f) {
103+
JsonGenerator.Feature old = f.mappedFeature();
104+
if (old != null) {
105+
disable(old);
106+
}
107+
return _this();
108+
}
109+
110+
@Override
111+
public JsonFactoryBuilder disable(JsonWriteFeature first, JsonWriteFeature... other) {
112+
disable(first);
113+
for (JsonWriteFeature f : other) {
114+
disable(f);
115+
}
116+
return _this();
117+
}
118+
119+
@Override
120+
public JsonFactoryBuilder configure(JsonWriteFeature f, boolean state) {
121+
return state ? enable(f) : disable(f);
122+
}
123+
124+
// // // JSON-specific helper objects
125+
80126
/**
81127
* Method for defining custom escapes factory uses for {@link JsonGenerator}s
82128
* it creates.

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

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public enum Feature {
8686
*<p>
8787
* Feature is enabled by default (since it is required by JSON specification).
8888
*/
89+
// @Deprecated
8990
QUOTE_FIELD_NAMES(true),
9091

9192
/**
@@ -100,6 +101,7 @@ public enum Feature {
100101
*<p>
101102
* Feature is enabled by default.
102103
*/
104+
// @Deprecated
103105
QUOTE_NON_NUMERIC_NUMBERS(true),
104106

105107
/**
@@ -117,6 +119,7 @@ public enum Feature {
117119
*<p>
118120
* Feature is disabled by default.
119121
*/
122+
// @Deprecated
120123
WRITE_NUMBERS_AS_STRINGS(false),
121124

122125
/**
@@ -146,6 +149,7 @@ public enum Feature {
146149
*<p>
147150
* Feature is disabled by default.
148151
*/
152+
// @Deprecated
149153
ESCAPE_NON_ASCII(false),
150154

151155
// 23-Nov-2015, tatu: for [core#223], if and when it gets implemented

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.core.io.InputDecorator;
44
import com.fasterxml.jackson.core.io.OutputDecorator;
55
import com.fasterxml.jackson.core.json.JsonReadFeature;
6+
import com.fasterxml.jackson.core.json.JsonWriteFeature;
67

78
/**
89
* Since 2.10, Builder class is offered for creating token stream factories
@@ -222,7 +223,29 @@ private B _failNonJSON(Object feature) {
222223
throw new IllegalArgumentException("Feature "+feature.getClass().getName()
223224
+"#"+feature.toString()+" not supported for non-JSON backend");
224225
}
225-
226+
227+
// // // JSON-specific, writes
228+
229+
public B enable(JsonWriteFeature f) {
230+
return _failNonJSON(f);
231+
}
232+
233+
public B enable(JsonWriteFeature first, JsonWriteFeature... other) {
234+
return _failNonJSON(first);
235+
}
236+
237+
public B disable(JsonWriteFeature f) {
238+
return _failNonJSON(f);
239+
}
240+
241+
public B disable(JsonWriteFeature first, JsonWriteFeature... other) {
242+
return _failNonJSON(first);
243+
}
244+
245+
public B configure(JsonWriteFeature f, boolean state) {
246+
return _failNonJSON(f);
247+
}
248+
226249
// // // Other configuration
227250

228251
public B inputDecorator(InputDecorator dec) {

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

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.fasterxml.jackson.core.json;
22

3-
import java.math.BigDecimal;
4-
53
import com.fasterxml.jackson.core.*;
64

75
/**
@@ -58,16 +56,6 @@ public enum JsonWriteFeature
5856
*/
5957
WRITE_NUMBERS_AS_STRINGS(false, JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS),
6058

61-
/**
62-
* Feature that determines whether {@link java.math.BigDecimal} entries are
63-
* serialized using {@link java.math.BigDecimal#toPlainString()} to prevent
64-
* values to be written using scientific notation.
65-
*<p>
66-
* Feature is disabled by default, so default output mode is used; this generally
67-
* depends on how {@link BigDecimal} has been created.
68-
*/
69-
WRITE_BIGDECIMAL_AS_PLAIN(false, JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN),
70-
7159
/**
7260
* Feature that specifies that all characters beyond 7-bit ASCII
7361
* range (i.e. code points of 128 and above) need to be output

0 commit comments

Comments
 (0)