Skip to content

Commit

Permalink
Fis #1773
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 24, 2017
1 parent 2122863 commit 9c553f9
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 181 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ Versions: 3.x (for earlier see VERSION-2.x)

#1762: `StdDateFormat`: serialize time offset using colon
#1772: Remove `MapperFeature. USE_STD_BEAN_NAMING`
#1773: Remove `MapperFeature.AUTO_DETECT_xxx` features


88 changes: 0 additions & 88 deletions src/main/java/com/fasterxml/jackson/databind/MapperFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,94 +63,6 @@ public enum MapperFeature implements ConfigFeature
*/
PROPAGATE_TRANSIENT_MARKER(false),

/*
/******************************************************
/* Introspection-based property auto-detection
/******************************************************
*/

/**
* Feature that determines whether "creator" methods are
* automatically detected by consider public constructors,
* and static single argument methods with name "valueOf".
* If disabled, only methods explicitly annotated are considered
* creator methods (except for the no-arg default constructor which
* is always considered a factory method).
*<p>
* Note that this feature has lower precedence than per-class
* annotations, and is only used if there isn't more granular
* configuration available.
*<P>
* Feature is enabled by default.
*/
AUTO_DETECT_CREATORS(true),

/**
* Feature that determines whether non-static fields are recognized as
* properties.
* If yes, then all public member fields
* are considered as properties. If disabled, only fields explicitly
* annotated are considered property fields.
*<p>
* Note that this feature has lower precedence than per-class
* annotations, and is only used if there isn't more granular
* configuration available.
*<p>
* Feature is enabled by default.
*/
AUTO_DETECT_FIELDS(true),

/**
* Feature that determines whether regular "getter" methods are
* automatically detected based on standard Bean naming convention
* or not. If yes, then all public zero-argument methods that
* start with prefix "get"
* are considered as getters.
* If disabled, only methods explicitly annotated are considered getters.
*<p>
* Note that since version 1.3, this does <b>NOT</b> include
* "is getters" (see {@link #AUTO_DETECT_IS_GETTERS} for details)
*<p>
* Note that this feature has lower precedence than per-class
* annotations, and is only used if there isn't more granular
* configuration available.
*<p>
* Feature is enabled by default.
*/
AUTO_DETECT_GETTERS(true),

/**
* Feature that determines whether "is getter" methods are
* automatically detected based on standard Bean naming convention
* or not. If yes, then all public zero-argument methods that
* start with prefix "is", and whose return type is boolean
* are considered as "is getters".
* If disabled, only methods explicitly annotated are considered getters.
*<p>
* Note that this feature has lower precedence than per-class
* annotations, and is only used if there isn't more granular
* configuration available.
*<p>
* Feature is enabled by default.
*/
AUTO_DETECT_IS_GETTERS(true),

/**
* Feature that determines whether "setter" methods are
* automatically detected based on standard Bean naming convention
* or not. If yes, then all public one-argument methods that
* start with prefix "set"
* are considered setters. If disabled, only methods explicitly
* annotated are considered setters.
*<p>
* Note that this feature has lower precedence than per-class
* annotations, and is only used if there isn't more granular
* configuration available.
*<P>
* Feature is enabled by default.
*/
AUTO_DETECT_SETTERS(true),

/**
* Feature that determines whether getters (getter methods)
* can be auto-detected if there is no matching mutator (setter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.*;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.core.Base64Variant;

import com.fasterxml.jackson.databind.*;
Expand All @@ -28,14 +27,6 @@ public abstract class MapperConfigBase<CFG extends ConfigFeature,

private final static int DEFAULT_MAPPER_FEATURES = collectFeatureDefaults(MapperFeature.class);

private final static int AUTO_DETECT_MASK =
MapperFeature.AUTO_DETECT_FIELDS.getMask()
| MapperFeature.AUTO_DETECT_GETTERS.getMask()
| MapperFeature.AUTO_DETECT_IS_GETTERS.getMask()
| MapperFeature.AUTO_DETECT_SETTERS.getMask()
| MapperFeature.AUTO_DETECT_CREATORS.getMask()
;

/*
/**********************************************************
/* Immutable config
Expand Down Expand Up @@ -651,29 +642,10 @@ public final JsonIgnoreProperties.Value getDefaultPropertyIgnorals(Class<?> base
@Override
public final VisibilityChecker<?> getDefaultVisibilityChecker()
{
VisibilityChecker<?> vchecker = _configOverrides.getDefaultVisibility();
// then global overrides (disabling)
if ((_mapperFeatures & AUTO_DETECT_MASK) != 0) {
if (!isEnabled(MapperFeature.AUTO_DETECT_FIELDS)) {
vchecker = vchecker.withFieldVisibility(Visibility.NONE);
}
if (!isEnabled(MapperFeature.AUTO_DETECT_GETTERS)) {
vchecker = vchecker.withGetterVisibility(Visibility.NONE);
}
if (!isEnabled(MapperFeature.AUTO_DETECT_IS_GETTERS)) {
vchecker = vchecker.withIsGetterVisibility(Visibility.NONE);
}
if (!isEnabled(MapperFeature.AUTO_DETECT_SETTERS)) {
vchecker = vchecker.withSetterVisibility(Visibility.NONE);
}
if (!isEnabled(MapperFeature.AUTO_DETECT_CREATORS)) {
vchecker = vchecker.withCreatorVisibility(Visibility.NONE);
}
}
return vchecker;
return _configOverrides.getDefaultVisibility();
}

@Override // since 2.9
@Override
public final VisibilityChecker<?> getDefaultVisibilityChecker(Class<?> baseType,
AnnotatedClass actualClass) {
VisibilityChecker<?> vc = getDefaultVisibilityChecker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,10 @@ protected void addBeanProps(DeserializationContext ctxt,
}
}
}
final boolean useGettersAsSetters = ctxt.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS)
&& ctxt.isEnabled(MapperFeature.AUTO_DETECT_GETTERS);
final boolean useGettersAsSetters = ctxt.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS);
// 24-Sep-2017, tatu: Legacy setting removed from 3.x, not sure if other visibility checks
// should be checked?
// && ctxt.isEnabled(MapperFeature.AUTO_DETECT_GETTERS);

// Ok: let's then filter out property definitions
List<BeanPropertyDefinition> propDefs = filterBeanProps(ctxt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,4 @@ public void testSubtypeResolver() throws Exception
mapper.setSubtypeResolver(repl);
assertSame(repl, mapper.getSubtypeResolver());
}

public void testMics() throws Exception
{
assertFalse(MapperFeature.AUTO_DETECT_FIELDS.enabledIn(0));
assertTrue(MapperFeature.AUTO_DETECT_FIELDS.enabledIn(-1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public void testFeatureDefaults()

// Expected defaults:
assertTrue(cfg.isEnabled(MapperFeature.USE_ANNOTATIONS));
assertTrue(cfg.isEnabled(MapperFeature.AUTO_DETECT_SETTERS));
assertTrue(cfg.isEnabled(MapperFeature.AUTO_DETECT_CREATORS));
assertTrue(cfg.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS));
assertTrue(cfg.isEnabled(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,7 @@ public void testCreator541() throws Exception

mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.disable(
MapperFeature.AUTO_DETECT_CREATORS,
MapperFeature.AUTO_DETECT_FIELDS,
MapperFeature.AUTO_DETECT_GETTERS,
MapperFeature.AUTO_DETECT_IS_GETTERS,
MapperFeature.AUTO_DETECT_SETTERS,
MapperFeature.USE_GETTERS_AS_SETTERS
);
mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

final String JSON = "{\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.*;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

Expand Down Expand Up @@ -360,7 +361,7 @@ public void testSimpleIgnoreAndRename()
public void testGlobalVisibilityForGetters()
{
ObjectMapper m = new ObjectMapper();
m.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
m.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
POJOPropertiesCollector coll = collector(m, SimpleGetterVisibility.class, true);
// should be 1, expect that we disabled getter auto-detection, so
Map<String, POJOPropertyBuilder> props = coll.getPropertyMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.fasterxml.jackson.databind.introspect;

import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;

Expand Down Expand Up @@ -34,15 +35,15 @@ static class PersonMixin extends ContactMixin implements Person {}
/**********************************************************
*/

// for [Issue#515]
// for [databind#515]
public void testDisappearingMixins515() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
mapper.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS)
.disable(MapperFeature.AUTO_DETECT_FIELDS)
.disable(MapperFeature.AUTO_DETECT_GETTERS)
.disable(MapperFeature.AUTO_DETECT_IS_GETTERS)
.disable(MapperFeature.INFER_PROPERTY_MUTATORS);
ObjectMapper mapper = new ObjectMapper()
.disable(MapperFeature.INFER_PROPERTY_MUTATORS);
mapper.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS);
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
SimpleModule module = new SimpleModule("Test");
module.setMixInAnnotation(Person.class, PersonMixin.class);
mapper.registerModule(module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,7 @@ public void testInferredNameConflictsWithSetters() throws Exception

public void testIssue541() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
mapper.disable(
MapperFeature.AUTO_DETECT_CREATORS,
MapperFeature.AUTO_DETECT_FIELDS,
MapperFeature.AUTO_DETECT_GETTERS,
MapperFeature.AUTO_DETECT_IS_GETTERS,
MapperFeature.AUTO_DETECT_SETTERS,
MapperFeature.USE_GETTERS_AS_SETTERS
);
mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
Bean541 data = mapper.readValue("{\"str\":\"the string\"}", Bean541.class);
if (data == null) {
throw new IllegalStateException("data is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void testGlobalAutoDetection() throws IOException
// Then auto-detection disabled. But note: we MUST create a new
// mapper, since old version of serializer may be cached by now
m = new ObjectMapper();
m.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
m.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
result = writeAndMap(m, new GetterClass());
assertEquals(1, result.size());
assertTrue(result.containsKey("x"));
Expand All @@ -107,7 +107,8 @@ public void testPerClassAutoDetection() throws IOException
assertTrue(result.containsKey("x"));

// And then class-level auto-detection enabling, should override defaults
m.configure(MapperFeature.AUTO_DETECT_GETTERS, true);
m.setVisibility(PropertyAccessor.GETTER, Visibility.PUBLIC_ONLY);

result = writeAndMap(m, new EnabledGetterClass());
assertEquals(2, result.size());
assertTrue(result.containsKey("x"));
Expand All @@ -118,33 +119,20 @@ public void testPerClassAutoDetectionForIsGetter() throws IOException
{
ObjectMapper m = new ObjectMapper();
// class level should override
m.configure(MapperFeature.AUTO_DETECT_GETTERS, true);
m.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
m.setVisibility(PropertyAccessor.GETTER, Visibility.PUBLIC_ONLY);
m.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);

Map<String,Object> result = writeAndMap(m, new EnabledIsGetterClass());
assertEquals(0, result.size());
assertFalse(result.containsKey("ok"));
}

// Simple test verifying that chainable methods work ok...
public void testConfigChainability()
{
ObjectMapper m = new ObjectMapper();
assertTrue(m.isEnabled(MapperFeature.AUTO_DETECT_SETTERS));
assertTrue(m.isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
m.configure(MapperFeature.AUTO_DETECT_SETTERS, false)
.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
assertFalse(m.isEnabled(MapperFeature.AUTO_DETECT_SETTERS));
assertFalse(m.isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
}

public void testVisibilityFeatures() throws Exception
{
ObjectMapper om = new ObjectMapper();
// Only use explicitly specified values to be serialized/deserialized (i.e., JSONProperty).
om.configure(MapperFeature.AUTO_DETECT_FIELDS, false);
om.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
om.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
om.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
om.setVisibility(PropertyAccessor.ALL, Visibility.NONE);

om.configure(MapperFeature.USE_GETTERS_AS_SETTERS, false);
om.configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
om.configure(MapperFeature.INFER_PROPERTY_MUTATORS, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,14 @@ public void testDefaults()

// First, defaults:
assertTrue(cfg.isEnabled(MapperFeature.USE_ANNOTATIONS));
assertTrue(cfg.isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
assertTrue(cfg.isEnabled(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS));

assertTrue(cfg.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS));

assertFalse(cfg.isEnabled(SerializationFeature.INDENT_OUTPUT));
assertFalse(cfg.isEnabled(MapperFeature.USE_STATIC_TYPING));

// since 1.3:
assertTrue(cfg.isEnabled(MapperFeature.AUTO_DETECT_IS_GETTERS));
// since 1.4

assertTrue(cfg.isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS));
// since 1.5
assertTrue(cfg.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));

}

public void testOverrideIntrospectors()
Expand Down

0 comments on commit 9c553f9

Please sign in to comment.