Skip to content

Commit fe24d94

Browse files
fduttonFaron Dutton
andauthored
#2990 Restores unintentional API changes (#2991)
Co-authored-by: Faron Dutton <[email protected]>
1 parent 7d6fe9a commit fe24d94

File tree

2 files changed

+106
-5
lines changed

2 files changed

+106
-5
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ 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+
177187
protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
178188
JavaType type, MixInResolver r, boolean forSerialization)
179189
{
@@ -184,6 +194,13 @@ protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
184194
return constructPropertyCollector(config, classDef, type, forSerialization, accNaming);
185195
}
186196

197+
@Deprecated
198+
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
199+
JavaType type, MixInResolver r, boolean forSerialization)
200+
{
201+
return collectPropertiesWithBuilder(config, type, r, null, forSerialization);
202+
}
203+
187204
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
188205
JavaType type, MixInResolver r, BeanDescription valueTypeDesc,
189206
boolean forSerialization)
@@ -194,6 +211,17 @@ protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> c
194211
return constructPropertyCollector(config, builderClassDef, type, forSerialization, accNaming);
195212
}
196213

214+
/**
215+
* Overridable method called for creating {@link POJOPropertiesCollector} instance
216+
* to use; override is needed if a custom sub-class is to be used.
217+
*/
218+
@Deprecated
219+
protected POJOPropertiesCollector constructPropertyCollector(MapperConfig<?> config,
220+
AnnotatedClass ac, JavaType type, boolean forSerialization, String mutatorPrefix)
221+
{
222+
return new POJOPropertiesCollector(config, forSerialization, type, ac, mutatorPrefix);
223+
}
224+
197225
// @since 2.12
198226
protected POJOPropertiesCollector constructPropertyCollector(MapperConfig<?> config,
199227
AnnotatedClass classDef, JavaType type, boolean forSerialization,

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

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

44+
/**
45+
* @since 2.5
46+
*/
47+
@Deprecated
48+
protected final boolean _stdBeanNaming;
49+
4450
/**
4551
* Type of POJO for which properties are being collected.
4652
*/
@@ -60,6 +66,13 @@ public class POJOPropertiesCollector
6066
*/
6167
protected final boolean _useAnnotations;
6268

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+
6376
/*
6477
/**********************************************************
6578
/* Collected property information
@@ -144,13 +157,28 @@ public class POJOPropertiesCollector
144157
/**********************************************************
145158
*/
146159

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+
147167
protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization,
148168
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)
149175
{
150176
_config = config;
177+
_stdBeanNaming = config.isEnabled(MapperFeature.USE_STD_BEAN_NAMING);
151178
_forSerialization = forSerialization;
152179
_type = type;
153180
_classDef = classDef;
181+
_mutatorPrefix = (mutatorPrefix == null) ? "set" : mutatorPrefix;
154182
if (config.isAnnotationProcessingEnabled()) {
155183
_useAnnotations = true;
156184
_annotationIntrospector = _config.getAnnotationIntrospector();
@@ -160,7 +188,8 @@ protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerializati
160188
}
161189
_visibilityChecker = _config.getDefaultVisibilityChecker(type.getRawClass(),
162190
classDef);
163-
_accessorNaming = accessorNaming;
191+
_accessorNaming = (null != accessorNaming) ? accessorNaming :
192+
new DefaultAccessorNamingStrategy.Provider().withSetterPrefix(mutatorPrefix).forPOJO(config, classDef);
164193
}
165194

166195
/*
@@ -964,7 +993,9 @@ protected void _renameProperties(Map<String, POJOPropertyBuilder> props)
964993
old.addAll(prop);
965994
}
966995
// replace the creatorProperty too, if there is one
967-
if (_updateCreatorProperty(prop, _creatorProperties)) {
996+
MonitoredList<POJOPropertyBuilder> monitored = MonitoredList.monitor(_creatorProperties);
997+
_updateCreatorProperty(prop, monitored);
998+
if (null != monitored && monitored.isModified()) {
968999
// [databind#2001]: New name of property was ignored previously? Remove from ignored
9691000
// 01-May-2018, tatu: I have a feeling this will need to be revisited at some point,
9701001
// to avoid removing some types of removals, possibly. But will do for now.
@@ -1276,17 +1307,59 @@ private PropertyNamingStrategy _findNamingStrategy()
12761307
_config.canOverrideAccessModifiers());
12771308
}
12781309

1279-
protected boolean _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
1310+
protected void _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
12801311

12811312
if (creatorProperties != null) {
12821313
final String intName = prop.getInternalName();
12831314
for (int i = 0, len = creatorProperties.size(); i < len; ++i) {
12841315
if (creatorProperties.get(i).getInternalName().equals(intName)) {
12851316
creatorProperties.set(i, prop);
1286-
return true;
1317+
break;
12871318
}
12881319
}
12891320
}
1290-
return false;
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+
}
12911364
}
12921365
}

0 commit comments

Comments
 (0)