Skip to content

Commit e01bcf9

Browse files
committed
Rewrote #2990
1 parent fe24d94 commit e01bcf9

File tree

4 files changed

+85
-101
lines changed

4 files changed

+85
-101
lines changed

release-notes/CREDITS-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,5 +1284,10 @@ Halil İbrahim Şener (hisener@github)
12841284
an annotated factory-based creator method (regression from 2.11)
12851285
(2.12.1)
12861286
1287+
Faron Dutton (fdutton@github)
1288+
1289+
* Contributed fix for #2990: Breaking API change in `BasicClassIntrospector` (2.12.0)
1290+
(2.12.1)
1291+
12871292
--- END ---
12881293

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project: jackson-databind
1515
(reported by zigzago@github)
1616
#2978: Fix failing `double` JsonCreators in jackson 2.12.0
1717
(contributed by Carter K)
18+
#2990: Breaking API change in `BasicClassIntrospector` (2.12.0)
19+
(reported, fix contributed by Faron D)
1820

1921
2.12.0 (29-Nov-2020)
2022

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,9 @@ public BasicBeanDescription forDirectClassAnnotations(MapperConfig<?> config,
174174
/**********************************************************
175175
*/
176176

177-
@Deprecated
178-
protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
179-
JavaType type, MixInResolver r, boolean forSerialization,
180-
String mutatorPrefix)
181-
{
182-
final AnnotatedClass classDef = _resolveAnnotatedClass(config, type, r);
183-
final AccessorNamingStrategy accNaming = new DefaultAccessorNamingStrategy.Provider().withSetterPrefix(mutatorPrefix).forPOJO(config, classDef);
184-
return constructPropertyCollector(config, classDef, type, forSerialization, accNaming);
185-
}
186-
177+
/**
178+
* @since 2.12
179+
*/
187180
protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
188181
JavaType type, MixInResolver r, boolean forSerialization)
189182
{
@@ -194,13 +187,19 @@ protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
194187
return constructPropertyCollector(config, classDef, type, forSerialization, accNaming);
195188
}
196189

197-
@Deprecated
198-
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
199-
JavaType type, MixInResolver r, boolean forSerialization)
190+
@Deprecated // since 2.12
191+
protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
192+
JavaType type, MixInResolver r, boolean forSerialization,
193+
String mutatorPrefix)
200194
{
201-
return collectPropertiesWithBuilder(config, type, r, null, forSerialization);
195+
final AnnotatedClass classDef = _resolveAnnotatedClass(config, type, r);
196+
final AccessorNamingStrategy accNaming = new DefaultAccessorNamingStrategy.Provider().withSetterPrefix(mutatorPrefix).forPOJO(config, classDef);
197+
return constructPropertyCollector(config, classDef, type, forSerialization, accNaming);
202198
}
203199

200+
/**
201+
* @since 2.12
202+
*/
204203
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
205204
JavaType type, MixInResolver r, BeanDescription valueTypeDesc,
206205
boolean forSerialization)
@@ -211,23 +210,32 @@ protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> c
211210
return constructPropertyCollector(config, builderClassDef, type, forSerialization, accNaming);
212211
}
213212

213+
@Deprecated // since 2.12
214+
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
215+
JavaType type, MixInResolver r, boolean forSerialization)
216+
{
217+
return collectPropertiesWithBuilder(config, type, r, null, forSerialization);
218+
}
219+
214220
/**
215221
* Overridable method called for creating {@link POJOPropertiesCollector} instance
216222
* to use; override is needed if a custom sub-class is to be used.
223+
*
224+
* @since 2.12
217225
*/
218-
@Deprecated
219226
protected POJOPropertiesCollector constructPropertyCollector(MapperConfig<?> config,
220-
AnnotatedClass ac, JavaType type, boolean forSerialization, String mutatorPrefix)
227+
AnnotatedClass classDef, JavaType type, boolean forSerialization,
228+
AccessorNamingStrategy accNaming)
221229
{
222-
return new POJOPropertiesCollector(config, forSerialization, type, ac, mutatorPrefix);
230+
return new POJOPropertiesCollector(config, forSerialization, type, classDef, accNaming);
223231
}
224232

225-
// @since 2.12
233+
@Deprecated // since 2.12
226234
protected POJOPropertiesCollector constructPropertyCollector(MapperConfig<?> config,
227-
AnnotatedClass classDef, JavaType type, boolean forSerialization,
228-
AccessorNamingStrategy accNaming)
235+
AnnotatedClass ac, JavaType type, boolean forSerialization,
236+
String mutatorPrefix)
229237
{
230-
return new POJOPropertiesCollector(config, forSerialization, type, classDef, accNaming);
238+
return new POJOPropertiesCollector(config, forSerialization, type, ac, mutatorPrefix);
231239
}
232240

233241
/**

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

Lines changed: 49 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ public class POJOPropertiesCollector
4141
*/
4242
protected final boolean _forSerialization;
4343

44-
/**
45-
* @since 2.5
46-
*/
47-
@Deprecated
48-
protected final boolean _stdBeanNaming;
49-
5044
/**
5145
* Type of POJO for which properties are being collected.
5246
*/
@@ -66,13 +60,6 @@ public class POJOPropertiesCollector
6660
*/
6761
protected final boolean _useAnnotations;
6862

69-
/**
70-
* Prefix used by auto-detected mutators ("setters"): usually "set",
71-
* but differs for builder objects ("with" by default).
72-
*/
73-
@Deprecated
74-
protected final String _mutatorPrefix;
75-
7663
/*
7764
/**********************************************************
7865
/* Collected property information
@@ -150,35 +137,38 @@ public class POJOPropertiesCollector
150137
* value injection.
151138
*/
152139
protected LinkedHashMap<Object, AnnotatedMember> _injectables;
140+
141+
// // // Deprecated entries to remove from 3.0
153142

143+
/**
144+
* @deprecated Since 2.12
145+
*/
146+
@Deprecated
147+
protected final boolean _stdBeanNaming;
148+
149+
/**
150+
* @deprecated Since 2.12
151+
*/
152+
@Deprecated
153+
protected String _mutatorPrefix = "set";
154+
154155
/*
155156
/**********************************************************
156157
/* Life-cycle
157158
/**********************************************************
158159
*/
159160

160-
@Deprecated
161-
protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization,
162-
JavaType type, AnnotatedClass classDef, String mutatorPrefix)
163-
{
164-
this(config, forSerialization, type, classDef, null, mutatorPrefix);
165-
}
166-
161+
/**
162+
* @since 2.12
163+
*/
167164
protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization,
168-
JavaType type, AnnotatedClass classDef, AccessorNamingStrategy accessorNaming)
169-
{
170-
this(config, forSerialization, type, classDef, accessorNaming, null);
171-
}
172-
173-
private POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization,
174-
JavaType type, AnnotatedClass classDef, AccessorNamingStrategy accessorNaming, String mutatorPrefix)
165+
JavaType type, AnnotatedClass classDef,
166+
AccessorNamingStrategy accessorNaming)
175167
{
176168
_config = config;
177-
_stdBeanNaming = config.isEnabled(MapperFeature.USE_STD_BEAN_NAMING);
178169
_forSerialization = forSerialization;
179170
_type = type;
180171
_classDef = classDef;
181-
_mutatorPrefix = (mutatorPrefix == null) ? "set" : mutatorPrefix;
182172
if (config.isAnnotationProcessingEnabled()) {
183173
_useAnnotations = true;
184174
_annotationIntrospector = _config.getAnnotationIntrospector();
@@ -188,8 +178,32 @@ private POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization
188178
}
189179
_visibilityChecker = _config.getDefaultVisibilityChecker(type.getRawClass(),
190180
classDef);
191-
_accessorNaming = (null != accessorNaming) ? accessorNaming :
192-
new DefaultAccessorNamingStrategy.Provider().withSetterPrefix(mutatorPrefix).forPOJO(config, classDef);
181+
_accessorNaming = accessorNaming;
182+
183+
// for backwards-compatibility only
184+
_stdBeanNaming = config.isEnabled(MapperFeature.USE_STD_BEAN_NAMING);
185+
}
186+
187+
/**
188+
* @deprecated Since 2.12
189+
*/
190+
@Deprecated
191+
protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization,
192+
JavaType type, AnnotatedClass classDef,
193+
String mutatorPrefix)
194+
{
195+
this(config, forSerialization, type, classDef,
196+
_accessorNaming(config, classDef, mutatorPrefix));
197+
_mutatorPrefix = mutatorPrefix;
198+
}
199+
200+
private static AccessorNamingStrategy _accessorNaming(MapperConfig<?> config, AnnotatedClass classDef,
201+
String mutatorPrefix) {
202+
if (mutatorPrefix == null) {
203+
mutatorPrefix = "set";
204+
}
205+
return new DefaultAccessorNamingStrategy.Provider()
206+
.withSetterPrefix(mutatorPrefix).forPOJO(config, classDef);
193207
}
194208

195209
/*
@@ -993,9 +1007,7 @@ protected void _renameProperties(Map<String, POJOPropertyBuilder> props)
9931007
old.addAll(prop);
9941008
}
9951009
// replace the creatorProperty too, if there is one
996-
MonitoredList<POJOPropertyBuilder> monitored = MonitoredList.monitor(_creatorProperties);
997-
_updateCreatorProperty(prop, monitored);
998-
if (null != monitored && monitored.isModified()) {
1010+
if (_updateCreatorProperty(prop, _creatorProperties)) {
9991011
// [databind#2001]: New name of property was ignored previously? Remove from ignored
10001012
// 01-May-2018, tatu: I have a feeling this will need to be revisited at some point,
10011013
// to avoid removing some types of removals, possibly. But will do for now.
@@ -1307,59 +1319,16 @@ private PropertyNamingStrategy _findNamingStrategy()
13071319
_config.canOverrideAccessModifiers());
13081320
}
13091321

1310-
protected void _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
1311-
1322+
protected boolean _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
13121323
if (creatorProperties != null) {
13131324
final String intName = prop.getInternalName();
13141325
for (int i = 0, len = creatorProperties.size(); i < len; ++i) {
13151326
if (creatorProperties.get(i).getInternalName().equals(intName)) {
13161327
creatorProperties.set(i, prop);
1317-
break;
1328+
return true;
13181329
}
13191330
}
13201331
}
1321-
}
1322-
1323-
private static class MonitoredList<T> extends AbstractList<T> {
1324-
private final List<T> delegate;
1325-
private boolean modified;
1326-
1327-
public MonitoredList(List<T> delegate) {
1328-
this.delegate = delegate;
1329-
this.modified = false;
1330-
}
1331-
1332-
@Override
1333-
public T get(int index) {
1334-
return this.delegate.get(index);
1335-
}
1336-
1337-
@Override
1338-
public int size() {
1339-
return this.delegate.size();
1340-
}
1341-
1342-
public T set(int index, T element) {
1343-
this.modified = true;
1344-
return this.delegate.set(index, element);
1345-
}
1346-
1347-
public void add(int index, T element) {
1348-
this.modified = true;
1349-
this.delegate.add(index, element);
1350-
}
1351-
1352-
public T remove(int index) {
1353-
this.modified = true;
1354-
return this.delegate.remove(index);
1355-
}
1356-
1357-
public boolean isModified() {
1358-
return this.modified;
1359-
}
1360-
1361-
public static <T> MonitoredList<T> monitor(List<T> source) {
1362-
return null == source ? null : new MonitoredList<>(source);
1363-
}
1332+
return false;
13641333
}
13651334
}

0 commit comments

Comments
 (0)