Skip to content

Commit 2122863

Browse files
committed
Fix #1772
1 parent 7b743fc commit 2122863

File tree

6 files changed

+33
-136
lines changed

6 files changed

+33
-136
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ Versions: 3.x (for earlier see VERSION-2.x)
88
3.0.0 (not yet released)
99

1010
#1762: `StdDateFormat`: serialize time offset using colon
11+
#1772: Remove `MapperFeature. USE_STD_BEAN_NAMING`
12+

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

-16
Original file line numberDiff line numberDiff line change
@@ -382,22 +382,6 @@ public enum MapperFeature implements ConfigFeature
382382
*/
383383
USE_WRAPPER_NAME_AS_PROPERTY_NAME(false),
384384

385-
/**
386-
* Feature that may be enabled to enforce strict compatibility with
387-
* Bean name introspection, instead of slightly different mechanism
388-
* Jackson defaults to.
389-
* Specific difference is that Jackson always lower cases leading upper-case
390-
* letters, so "getURL()" becomes "url" property; whereas standard Bean
391-
* naming <b>only</b> lower-cases the first letter if it is NOT followed by
392-
* another upper-case letter (so "getURL()" would result in "URL" property).
393-
*<p>
394-
* Feature is disabled by default for backwards compatibility purposes: earlier
395-
* Jackson versions used Jackson's own mechanism.
396-
*
397-
* @since 2.5
398-
*/
399-
USE_STD_BEAN_NAMING(false),
400-
401385
/**
402386
* Feature that when enabled will allow explicitly named properties (i.e., fields or methods
403387
* annotated with {@link com.fasterxml.jackson.annotation.JsonProperty}("explicitName")) to

src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ public class POJOPropertiesCollector
3737
*/
3838
protected final boolean _forSerialization;
3939

40-
/**
41-
* @since 2.5
42-
*/
43-
protected final boolean _stdBeanNaming;
44-
4540
/**
4641
* Type of POJO for which properties are being collected.
4742
*/
@@ -127,7 +122,6 @@ protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerializati
127122
JavaType type, AnnotatedClass classDef, String mutatorPrefix)
128123
{
129124
_config = config;
130-
_stdBeanNaming = config.isEnabled(MapperFeature.USE_STD_BEAN_NAMING);
131125
_forSerialization = forSerialization;
132126
_type = type;
133127
_classDef = classDef;
@@ -566,10 +560,10 @@ protected void _addGetterMethod(Map<String, POJOPropertyBuilder> props,
566560
if (!nameExplicit) { // no explicit name; must consider implicit
567561
implName = ai.findImplicitPropertyName(m);
568562
if (implName == null) {
569-
implName = BeanUtil.okNameForRegularGetter(m, m.getName(), _stdBeanNaming);
563+
implName = BeanUtil.okNameForRegularGetter(m, m.getName());
570564
}
571565
if (implName == null) { // if not, must skip
572-
implName = BeanUtil.okNameForIsGetter(m, m.getName(), _stdBeanNaming);
566+
implName = BeanUtil.okNameForIsGetter(m, m.getName());
573567
if (implName == null) {
574568
return;
575569
}
@@ -581,7 +575,7 @@ protected void _addGetterMethod(Map<String, POJOPropertyBuilder> props,
581575
// we still need implicit name to link with other pieces
582576
implName = ai.findImplicitPropertyName(m);
583577
if (implName == null) {
584-
implName = BeanUtil.okNameForGetter(m, _stdBeanNaming);
578+
implName = BeanUtil.okNameForGetter(m);
585579
}
586580
// if not regular getter name, use method name as is
587581
if (implName == null) {
@@ -608,7 +602,7 @@ protected void _addSetterMethod(Map<String, POJOPropertyBuilder> props,
608602
if (!nameExplicit) { // no explicit name; must follow naming convention
609603
implName = (ai == null) ? null : ai.findImplicitPropertyName(m);
610604
if (implName == null) {
611-
implName = BeanUtil.okNameForMutator(m, _mutatorPrefix, _stdBeanNaming);
605+
implName = BeanUtil.okNameForMutator(m, _mutatorPrefix);
612606
}
613607
if (implName == null) { // if not, must skip
614608
return;
@@ -618,7 +612,7 @@ protected void _addSetterMethod(Map<String, POJOPropertyBuilder> props,
618612
// we still need implicit name to link with other pieces
619613
implName = (ai == null) ? null : ai.findImplicitPropertyName(m);
620614
if (implName == null) {
621-
implName = BeanUtil.okNameForMutator(m, _mutatorPrefix, _stdBeanNaming);
615+
implName = BeanUtil.okNameForMutator(m, _mutatorPrefix);
622616
}
623617
// if not regular getter name, use method name as is
624618
if (implName == null) {

src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java

+15-74
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import com.fasterxml.jackson.annotation.JsonInclude;
88
import com.fasterxml.jackson.databind.JavaType;
9-
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
9+
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
1010

1111
/**
1212
* Helper class that contains functionality needed by both serialization
@@ -20,17 +20,16 @@ public class BeanUtil
2020
/**********************************************************
2121
*/
2222

23-
public static String okNameForGetter(AnnotatedMethod am, boolean stdNaming) {
23+
public static String okNameForGetter(AnnotatedMember am) {
2424
String name = am.getName();
25-
String str = okNameForIsGetter(am, name, stdNaming);
25+
String str = okNameForIsGetter(am, name);
2626
if (str == null) {
27-
str = okNameForRegularGetter(am, name, stdNaming);
27+
str = okNameForRegularGetter(am, name);
2828
}
2929
return str;
3030
}
3131

32-
public static String okNameForRegularGetter(AnnotatedMethod am, String name,
33-
boolean stdNaming)
32+
public static String okNameForRegularGetter(AnnotatedMember am, String name)
3433
{
3534
if (name.startsWith("get")) {
3635
/* 16-Feb-2009, tatu: To handle [JACKSON-53], need to block
@@ -50,38 +49,27 @@ public static String okNameForRegularGetter(AnnotatedMethod am, String name,
5049
return null;
5150
}
5251
}
53-
return stdNaming
54-
? stdManglePropertyName(name, 3)
55-
: legacyManglePropertyName(name, 3);
52+
return stdManglePropertyName(name, 3);
5653
}
5754
return null;
5855
}
5956

60-
/**
61-
* @since 2.5
62-
*/
63-
public static String okNameForIsGetter(AnnotatedMethod am, String name,
64-
boolean stdNaming)
57+
public static String okNameForIsGetter(AnnotatedMember am, String name)
6558
{
6659
if (name.startsWith("is")) { // plus, must return a boolean
6760
Class<?> rt = am.getRawType();
6861
if (rt == Boolean.class || rt == Boolean.TYPE) {
69-
return stdNaming
70-
? stdManglePropertyName(name, 2)
71-
: legacyManglePropertyName(name, 2);
62+
return stdManglePropertyName(name, 2);
7263
}
7364
}
7465
return null;
7566
}
7667

77-
public static String okNameForMutator(AnnotatedMethod am, String prefix,
78-
boolean stdNaming)
68+
public static String okNameForMutator(AnnotatedMember am, String prefix)
7969
{
8070
String name = am.getName();
8171
if (name.startsWith(prefix)) {
82-
return stdNaming
83-
? stdManglePropertyName(name, prefix.length())
84-
: legacyManglePropertyName(name, prefix.length());
72+
return stdManglePropertyName(name, prefix.length());
8573
}
8674
return null;
8775
}
@@ -148,7 +136,7 @@ public static Object getDefaultValue(JavaType type)
148136
* indeed injectect by Cglib. We do this by verifying that the
149137
* result type is "net.sf.cglib.proxy.Callback[]"
150138
*/
151-
protected static boolean isCglibGetCallbacks(AnnotatedMethod am)
139+
protected static boolean isCglibGetCallbacks(AnnotatedMember am)
152140
{
153141
Class<?> rt = am.getRawType();
154142
// Ok, first: must return an array type
@@ -173,21 +161,10 @@ protected static boolean isCglibGetCallbacks(AnnotatedMethod am)
173161
return false;
174162
}
175163

176-
/**
177-
* Similar to {@link #isCglibGetCallbacks}, need to suppress
178-
* a cyclic reference.
179-
*/
180-
protected static boolean isGroovyMetaClassSetter(AnnotatedMethod am)
181-
{
182-
Class<?> argType = am.getRawParameterType(0);
183-
String pkgName = ClassUtil.getPackageName(argType);
184-
return (pkgName != null) && pkgName.startsWith("groovy.lang");
185-
}
186-
187164
/**
188165
* Another helper method to deal with Groovy's problematic metadata accessors
189166
*/
190-
protected static boolean isGroovyMetaClassGetter(AnnotatedMethod am)
167+
protected static boolean isGroovyMetaClassGetter(AnnotatedMember am)
191168
{
192169
String pkgName = ClassUtil.getPackageName(am.getRawType());
193170
return (pkgName != null) && pkgName.startsWith("groovy.lang");
@@ -199,45 +176,9 @@ protected static boolean isGroovyMetaClassGetter(AnnotatedMethod am)
199176
/**********************************************************
200177
*/
201178

202-
/**
203-
* Method called to figure out name of the property, given
204-
* corresponding suggested name based on a method or field name.
205-
*
206-
* @param basename Name of accessor/mutator method, not including prefix
207-
* ("get"/"is"/"set")
208-
*/
209-
protected static String legacyManglePropertyName(final String basename, final int offset)
210-
{
211-
final int end = basename.length();
212-
if (end == offset) { // empty name, nope
213-
return null;
214-
}
215-
// next check: is the first character upper case? If not, return as is
216-
char c = basename.charAt(offset);
217-
char d = Character.toLowerCase(c);
218-
219-
if (c == d) {
220-
return basename.substring(offset);
221-
}
222-
// otherwise, lower case initial chars. Common case first, just one char
223-
StringBuilder sb = new StringBuilder(end - offset);
224-
sb.append(d);
225-
int i = offset+1;
226-
for (; i < end; ++i) {
227-
c = basename.charAt(i);
228-
d = Character.toLowerCase(c);
229-
if (c == d) {
230-
sb.append(basename, i, end);
231-
break;
232-
}
233-
sb.append(d);
234-
}
235-
return sb.toString();
236-
}
237-
238-
/**
239-
* @since 2.5
240-
*/
179+
// 24-Sep-2017, tatu: note that "std" here refers to earlier (1.x, 2.x) distinction
180+
// between "legacy" (slightly non-conforming) and "std" (fully conforming): with 3.x
181+
// only latter exists.
241182
protected static String stdManglePropertyName(final String basename, final int offset)
242183
{
243184
final int end = basename.length();

src/test/java/com/fasterxml/jackson/databind/introspect/BeanNamingTest.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@ public int getA() {
1616
return 3;
1717
}
1818
}
19-
20-
public void testSimple() throws Exception
21-
{
22-
ObjectMapper mapper = new ObjectMapper();
23-
assertFalse(mapper.isEnabled(MapperFeature.USE_STD_BEAN_NAMING));
24-
assertEquals(aposToQuotes("{'url':'http://foo'}"),
25-
mapper.writeValueAsString(new URLBean()));
26-
assertEquals(aposToQuotes("{'a':3}"),
27-
mapper.writeValueAsString(new ABean()));
2819

29-
mapper = new ObjectMapper();
30-
mapper.enable(MapperFeature.USE_STD_BEAN_NAMING);
20+
// 24-Sep-2017, tatu: Used to test for `MapperFeature.USE_STD_BEAN_NAMING`, but with 3.x
21+
// that is always enabled.
22+
public void testMultipleLeadingCapitalLetters() throws Exception
23+
{
24+
ObjectMapper mapper = objectMapper();
3125
assertEquals(aposToQuotes("{'URL':'http://foo'}"),
3226
mapper.writeValueAsString(new URLBean()));
3327
assertEquals(aposToQuotes("{'a':3}"),

src/test/java/com/fasterxml/jackson/databind/util/BeanUtilTest.java

+6-24
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ public void set() { }
3737

3838
public void testNameMangle()
3939
{
40-
assertEquals("foo", BeanUtil.legacyManglePropertyName("getFoo", 3));
4140
assertEquals("foo", BeanUtil.stdManglePropertyName("getFoo", 3));
4241

43-
assertEquals("url", BeanUtil.legacyManglePropertyName("getURL", 3));
4442
assertEquals("URL", BeanUtil.stdManglePropertyName("getURL", 3));
4543
}
4644

@@ -98,45 +96,29 @@ public void testOkNameForSetter() throws Exception
9896
*/
9997

10098
private void _testIsGetter(String name, String expName) throws Exception {
101-
_testIsGetter(name, expName, true);
102-
_testIsGetter(name, expName, false);
103-
}
104-
105-
private void _testIsGetter(String name, String expName, boolean useStd) throws Exception
106-
{
10799
AnnotatedMethod m = _method(IsGetters.class, name);
108100
if (expName == null) {
109-
assertNull(BeanUtil.okNameForIsGetter(m, name, useStd));
101+
assertNull(BeanUtil.okNameForIsGetter(m, name));
110102
} else {
111-
assertEquals(expName, BeanUtil.okNameForIsGetter(m, name, useStd));
103+
assertEquals(expName, BeanUtil.okNameForIsGetter(m, name));
112104
}
113105
}
114106

115107
private void _testOkNameForGetter(String name, String expName) throws Exception {
116-
_testOkNameForGetter(name, expName, true);
117-
_testOkNameForGetter(name, expName, false);
118-
}
119-
120-
private void _testOkNameForGetter(String name, String expName, boolean useStd) throws Exception {
121108
AnnotatedMethod m = _method(Getters.class, name);
122109
if (expName == null) {
123-
assertNull(BeanUtil.okNameForGetter(m, useStd));
110+
assertNull(BeanUtil.okNameForGetter(m));
124111
} else {
125-
assertEquals(expName, BeanUtil.okNameForGetter(m, useStd));
112+
assertEquals(expName, BeanUtil.okNameForGetter(m));
126113
}
127114
}
128115

129116
private void _testOkNameForMutator(String name, String expName) throws Exception {
130-
_testOkNameForMutator(name, expName, true);
131-
_testOkNameForMutator(name, expName, false);
132-
}
133-
134-
private void _testOkNameForMutator(String name, String expName, boolean useStd) throws Exception {
135117
AnnotatedMethod m = _method(Setters.class, name);
136118
if (expName == null) {
137-
assertNull(BeanUtil.okNameForMutator(m, "set", useStd));
119+
assertNull(BeanUtil.okNameForMutator(m, "set"));
138120
} else {
139-
assertEquals(expName, BeanUtil.okNameForMutator(m, "set", useStd));
121+
assertEquals(expName, BeanUtil.okNameForMutator(m, "set"));
140122
}
141123
}
142124

0 commit comments

Comments
 (0)