Skip to content

Commit 842597e

Browse files
committed
Fixed #3033
1 parent e43c350 commit 842597e

File tree

8 files changed

+89
-45
lines changed

8 files changed

+89
-45
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Project: jackson-databind
1313
#3002: Add `DeserializationContext.readTreeAsValue()` methods for more convenient
1414
conversions for deserializers to use
1515
#3011: Clean up support of typed "unmodifiable", "singleton" Maps/Sets/Collections
16+
#3033: Extend internal bitfield of `MapperFeature` to be `long`
1617
#3035: Add `removeMixIn()` method in `MapperBuilder`
1718
#3036: Backport `MapperBuilder` lambda-taking methods: `withConfigOverride()`,
1819
`withCoercionConfig()`, `withCoercionConfigDefaults()`

src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected DeserializationConfig(DeserializationConfig src,
174174
*/
175175

176176
private DeserializationConfig(DeserializationConfig src,
177-
int mapperFeatures, int deserFeatures,
177+
long mapperFeatures, int deserFeatures,
178178
int parserFeatures, int parserFeatureMask,
179179
int formatFeatures, int formatFeatureMask)
180180
{
@@ -331,16 +331,16 @@ protected DeserializationConfig(DeserializationConfig src, SimpleMixInResolver m
331331
/**********************************************************
332332
*/
333333

334-
@Override // since 2.9
334+
@Override
335335
protected final DeserializationConfig _withBase(BaseSettings newBase) {
336336
return (_base == newBase) ? this : new DeserializationConfig(this, newBase);
337337
}
338338

339-
@Override // since 2.9
340-
protected final DeserializationConfig _withMapperFeatures(int mapperFeatures) {
339+
@Override
340+
protected final DeserializationConfig _withMapperFeatures(long mapperFeatures) {
341341
return new DeserializationConfig(this, mapperFeatures, _deserFeatures,
342-
_parserFeatures, _parserFeaturesToChange,
343-
_formatReadFeatures, _formatReadFeaturesToChange);
342+
_parserFeatures, _parserFeaturesToChange,
343+
_formatReadFeatures, _formatReadFeaturesToChange);
344344
}
345345

346346
/*

src/main/java/com/fasterxml/jackson/databind/MapperFeature.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,19 +574,48 @@ public enum MapperFeature implements ConfigFeature
574574
;
575575

576576
private final boolean _defaultState;
577-
private final int _mask;
578-
577+
private final long _mask;
578+
579+
// @since 2.13
580+
public static int collectLongDefaults() {
581+
int flags = 0;
582+
for (MapperFeature value : MapperFeature.values()) {
583+
if (value.enabledByDefault()) {
584+
flags |= value.getLongMask();
585+
}
586+
}
587+
return flags;
588+
}
589+
579590
private MapperFeature(boolean defaultState) {
580591
_defaultState = defaultState;
581-
_mask = (1 << ordinal());
592+
_mask = (1L << ordinal());
582593
}
583594

584595
@Override
585596
public boolean enabledByDefault() { return _defaultState; }
586597

587598
@Override
588-
public int getMask() { return _mask; }
599+
@Deprecated // 2.13
600+
public int getMask() {
601+
// 25-Feb-2021, tatu: Not 100% sure what to do here; should not be
602+
// called any more
603+
return (int) _mask;
604+
}
605+
606+
// @since 2.13
607+
public long getLongMask() {
608+
return _mask;
609+
}
589610

590611
@Override
591-
public boolean enabledIn(int flags) { return (flags & _mask) != 0; }
612+
@Deprecated
613+
public boolean enabledIn(int flags) {
614+
return (flags & _mask) != 0;
615+
}
616+
617+
// @since 2.13
618+
public boolean enabledIn(long flags) {
619+
return (flags & _mask) != 0;
620+
}
592621
}

src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,9 +2454,10 @@ public boolean isEnabled(MapperFeature f) {
24542454
return _serializationConfig.isEnabled(f);
24552455
}
24562456

2457-
// Note: planned to be deprecated in 2.11 (not needed with 2.10):
2458-
// @deprecated Since 2.10 use {@code JsonMapper.builder().configure(...)} (or similarly for other datatypes)
2459-
// @Deprecated
2457+
/**
2458+
* @deprecated Since 2.13 use {@code JsonMapper.builder().configure(...)}
2459+
*/
2460+
@Deprecated
24602461
public ObjectMapper configure(MapperFeature f, boolean state) {
24612462
_serializationConfig = state ?
24622463
_serializationConfig.with(f) : _serializationConfig.without(f);
@@ -2465,18 +2466,20 @@ public ObjectMapper configure(MapperFeature f, boolean state) {
24652466
return this;
24662467
}
24672468

2468-
// Note: planned to be deprecated in 2.11 (not needed with 2.10):
2469-
// @deprecated Since 2.10 use {@code JsonMapper.builder().Enable(...)} (or similarly for other datatypes)
2470-
// @Deprecated
2469+
/**
2470+
* @deprecated Since 2.13 use {@code JsonMapper.builder().enable(...)}
2471+
*/
2472+
@Deprecated
24712473
public ObjectMapper enable(MapperFeature... f) {
24722474
_deserializationConfig = _deserializationConfig.with(f);
24732475
_serializationConfig = _serializationConfig.with(f);
24742476
return this;
24752477
}
24762478

2477-
// Note: planned to be deprecated in 2.11 (not needed with 2.10):
2478-
// @deprecated Since 2.10 use {@code JsonMapper.builder().disable(...)} (or similarly for other datatypes)
2479-
// @Deprecated
2479+
/**
2480+
* @deprecated Since 2.13 use {@code JsonMapper.builder().disable(...)}
2481+
*/
2482+
@Deprecated
24802483
public ObjectMapper disable(MapperFeature... f) {
24812484
_deserializationConfig = _deserializationConfig.without(f);
24822485
_serializationConfig = _serializationConfig.without(f);

src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private SerializationConfig(SerializationConfig src, SubtypeResolver str)
176176
}
177177

178178
private SerializationConfig(SerializationConfig src,
179-
int mapperFeatures, int serFeatures,
179+
long mapperFeatures, int serFeatures,
180180
int generatorFeatures, int generatorFeatureMask,
181181
int formatFeatures, int formatFeaturesMask)
182182
{
@@ -289,13 +289,13 @@ protected SerializationConfig(SerializationConfig src, PrettyPrinter defaultPP)
289289
/**********************************************************
290290
*/
291291

292-
@Override // since 2.9
292+
@Override
293293
protected final SerializationConfig _withBase(BaseSettings newBase) {
294294
return (_base == newBase) ? this : new SerializationConfig(this, newBase);
295295
}
296296

297-
@Override // since 2.9
298-
protected final SerializationConfig _withMapperFeatures(int mapperFeatures) {
297+
@Override
298+
protected final SerializationConfig _withMapperFeatures(long mapperFeatures) {
299299
return new SerializationConfig(this, mapperFeatures, _serFeatures,
300300
_generatorFeatures, _generatorFeaturesToChange,
301301
_formatWriteFeatures, _formatWriteFeaturesToChange);

src/main/java/com/fasterxml/jackson/databind/cfg/MapperBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,19 @@ public TokenStreamFactory streamFactory() {
101101
/**********************************************************************
102102
*/
103103

104+
@SuppressWarnings("deprecation")
104105
public B enable(MapperFeature... features) {
105106
_mapper.enable(features);
106107
return _this();
107108
}
108109

110+
@SuppressWarnings("deprecation")
109111
public B disable(MapperFeature... features) {
110112
_mapper.disable(features);
111113
return _this();
112114
}
113115

116+
@SuppressWarnings("deprecation")
114117
public B configure(MapperFeature feature, boolean state) {
115118
_mapper.configure(feature, state);
116119
return _this();

src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfig.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import java.util.TimeZone;
66

77
import com.fasterxml.jackson.annotation.*;
8+
89
import com.fasterxml.jackson.core.Base64Variant;
910
import com.fasterxml.jackson.core.SerializableString;
1011
import com.fasterxml.jackson.core.io.SerializedString;
1112
import com.fasterxml.jackson.core.type.TypeReference;
13+
1214
import com.fasterxml.jackson.databind.*;
1315
import com.fasterxml.jackson.databind.introspect.AccessorNamingStrategy;
1416
import com.fasterxml.jackson.databind.introspect.Annotated;
@@ -55,9 +57,12 @@ public abstract class MapperConfig<T extends MapperConfig<T>>
5557

5658
/**
5759
* Set of shared mapper features enabled.
60+
*<p>
61+
* NOTE: changed from {@code int} (in Jackson 2.12 and prior} to {@code long}
62+
* (2.13 and later)
5863
*/
59-
protected final int _mapperFeatures;
60-
64+
protected final long _mapperFeatures;
65+
6166
/**
6267
* Immutable container object for simple configuration settings.
6368
*/
@@ -69,13 +74,13 @@ public abstract class MapperConfig<T extends MapperConfig<T>>
6974
/**********************************************************
7075
*/
7176

72-
protected MapperConfig(BaseSettings base, int mapperFeatures)
77+
protected MapperConfig(BaseSettings base, long mapperFeatures)
7378
{
7479
_base = base;
7580
_mapperFeatures = mapperFeatures;
7681
}
7782

78-
protected MapperConfig(MapperConfig<T> src, int mapperFeatures)
83+
protected MapperConfig(MapperConfig<T> src, long mapperFeatures)
7984
{
8085
_base = src._base;
8186
_mapperFeatures = mapperFeatures;
@@ -92,7 +97,7 @@ protected MapperConfig(MapperConfig<T> src)
9297
_base = src._base;
9398
_mapperFeatures = src._mapperFeatures;
9499
}
95-
100+
96101
/**
97102
* Method that calculates bit set (flags) of all features that
98103
* are enabled by default.
@@ -150,7 +155,10 @@ public final boolean isEnabled(MapperFeature f) {
150155
* mask are enabled.
151156
*
152157
* @since 2.3
158+
*
159+
* @deprecated Since 2.13 -- no replacement
153160
*/
161+
@Deprecated
154162
public final boolean hasMapperFeatures(int featureMask) {
155163
return (_mapperFeatures & featureMask) == featureMask;
156164
}

src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ public abstract class MapperConfigBase<CFG extends ConfigFeature,
3030
*/
3131
protected final static ConfigOverride EMPTY_OVERRIDE = ConfigOverride.empty();
3232

33-
private final static int DEFAULT_MAPPER_FEATURES = collectFeatureDefaults(MapperFeature.class);
33+
private final static long DEFAULT_MAPPER_FEATURES = MapperFeature.collectLongDefaults();
3434

3535
/**
3636
* @since 2.9
3737
*/
38-
private final static int AUTO_DETECT_MASK =
39-
MapperFeature.AUTO_DETECT_FIELDS.getMask()
40-
| MapperFeature.AUTO_DETECT_GETTERS.getMask()
41-
| MapperFeature.AUTO_DETECT_IS_GETTERS.getMask()
42-
| MapperFeature.AUTO_DETECT_SETTERS.getMask()
43-
| MapperFeature.AUTO_DETECT_CREATORS.getMask()
38+
private final static long AUTO_DETECT_MASK =
39+
MapperFeature.AUTO_DETECT_FIELDS.getLongMask()
40+
| MapperFeature.AUTO_DETECT_GETTERS.getLongMask()
41+
| MapperFeature.AUTO_DETECT_IS_GETTERS.getLongMask()
42+
| MapperFeature.AUTO_DETECT_SETTERS.getLongMask()
43+
| MapperFeature.AUTO_DETECT_CREATORS.getLongMask()
4444
;
4545

4646
/*
@@ -184,7 +184,7 @@ protected MapperConfigBase(MapperConfigBase<CFG,T> src, BaseSettings base)
184184
_configOverrides = src._configOverrides;
185185
}
186186

187-
protected MapperConfigBase(MapperConfigBase<CFG,T> src, int mapperFeatures)
187+
protected MapperConfigBase(MapperConfigBase<CFG,T> src, long mapperFeatures)
188188
{
189189
super(src, mapperFeatures);
190190
_mixIns = src._mixIns;
@@ -274,7 +274,7 @@ protected MapperConfigBase(MapperConfigBase<CFG,T> src, ContextAttributes attr)
274274
/**
275275
* @since 2.9 (in this case, demoted from sub-classes)
276276
*/
277-
protected abstract T _withMapperFeatures(int mapperFeatures);
277+
protected abstract T _withMapperFeatures(long mapperFeatures);
278278

279279
/*
280280
/**********************************************************
@@ -290,9 +290,9 @@ protected MapperConfigBase(MapperConfigBase<CFG,T> src, ContextAttributes attr)
290290
@Override
291291
public final T with(MapperFeature... features)
292292
{
293-
int newMapperFlags = _mapperFeatures;
293+
long newMapperFlags = _mapperFeatures;
294294
for (MapperFeature f : features) {
295-
newMapperFlags |= f.getMask();
295+
newMapperFlags |= f.getLongMask();
296296
}
297297
if (newMapperFlags == _mapperFeatures) {
298298
return (T) this;
@@ -308,9 +308,9 @@ public final T with(MapperFeature... features)
308308
@Override
309309
public final T without(MapperFeature... features)
310310
{
311-
int newMapperFlags = _mapperFeatures;
311+
long newMapperFlags = _mapperFeatures;
312312
for (MapperFeature f : features) {
313-
newMapperFlags &= ~f.getMask();
313+
newMapperFlags &= ~f.getLongMask();
314314
}
315315
if (newMapperFlags == _mapperFeatures) {
316316
return (T) this;
@@ -322,11 +322,11 @@ public final T without(MapperFeature... features)
322322
@Override
323323
public final T with(MapperFeature feature, boolean state)
324324
{
325-
int newMapperFlags;
325+
long newMapperFlags;
326326
if (state) {
327-
newMapperFlags = _mapperFeatures | feature.getMask();
327+
newMapperFlags = _mapperFeatures | feature.getLongMask();
328328
} else {
329-
newMapperFlags = _mapperFeatures & ~feature.getMask();
329+
newMapperFlags = _mapperFeatures & ~feature.getLongMask();
330330
}
331331
if (newMapperFlags == _mapperFeatures) {
332332
return (T) this;

0 commit comments

Comments
 (0)