Skip to content

Commit

Permalink
Rewrote #2990
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 18, 2020
1 parent fe24d94 commit e01bcf9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 101 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1284,5 +1284,10 @@ Halil İbrahim Şener (hisener@github)
an annotated factory-based creator method (regression from 2.11)
(2.12.1)
Faron Dutton (fdutton@github)
* Contributed fix for #2990: Breaking API change in `BasicClassIntrospector` (2.12.0)
(2.12.1)
--- END ---
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project: jackson-databind
(reported by zigzago@github)
#2978: Fix failing `double` JsonCreators in jackson 2.12.0
(contributed by Carter K)
#2990: Breaking API change in `BasicClassIntrospector` (2.12.0)
(reported, fix contributed by Faron D)

2.12.0 (29-Nov-2020)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,9 @@ public BasicBeanDescription forDirectClassAnnotations(MapperConfig<?> config,
/**********************************************************
*/

@Deprecated
protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
JavaType type, MixInResolver r, boolean forSerialization,
String mutatorPrefix)
{
final AnnotatedClass classDef = _resolveAnnotatedClass(config, type, r);
final AccessorNamingStrategy accNaming = new DefaultAccessorNamingStrategy.Provider().withSetterPrefix(mutatorPrefix).forPOJO(config, classDef);
return constructPropertyCollector(config, classDef, type, forSerialization, accNaming);
}

/**
* @since 2.12
*/
protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
JavaType type, MixInResolver r, boolean forSerialization)
{
Expand All @@ -194,13 +187,19 @@ protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
return constructPropertyCollector(config, classDef, type, forSerialization, accNaming);
}

@Deprecated
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
JavaType type, MixInResolver r, boolean forSerialization)
@Deprecated // since 2.12
protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
JavaType type, MixInResolver r, boolean forSerialization,
String mutatorPrefix)
{
return collectPropertiesWithBuilder(config, type, r, null, forSerialization);
final AnnotatedClass classDef = _resolveAnnotatedClass(config, type, r);
final AccessorNamingStrategy accNaming = new DefaultAccessorNamingStrategy.Provider().withSetterPrefix(mutatorPrefix).forPOJO(config, classDef);
return constructPropertyCollector(config, classDef, type, forSerialization, accNaming);
}

/**
* @since 2.12
*/
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
JavaType type, MixInResolver r, BeanDescription valueTypeDesc,
boolean forSerialization)
Expand All @@ -211,23 +210,32 @@ protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> c
return constructPropertyCollector(config, builderClassDef, type, forSerialization, accNaming);
}

@Deprecated // since 2.12
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
JavaType type, MixInResolver r, boolean forSerialization)
{
return collectPropertiesWithBuilder(config, type, r, null, forSerialization);
}

/**
* Overridable method called for creating {@link POJOPropertiesCollector} instance
* to use; override is needed if a custom sub-class is to be used.
*
* @since 2.12
*/
@Deprecated
protected POJOPropertiesCollector constructPropertyCollector(MapperConfig<?> config,
AnnotatedClass ac, JavaType type, boolean forSerialization, String mutatorPrefix)
AnnotatedClass classDef, JavaType type, boolean forSerialization,
AccessorNamingStrategy accNaming)
{
return new POJOPropertiesCollector(config, forSerialization, type, ac, mutatorPrefix);
return new POJOPropertiesCollector(config, forSerialization, type, classDef, accNaming);
}

// @since 2.12
@Deprecated // since 2.12
protected POJOPropertiesCollector constructPropertyCollector(MapperConfig<?> config,
AnnotatedClass classDef, JavaType type, boolean forSerialization,
AccessorNamingStrategy accNaming)
AnnotatedClass ac, JavaType type, boolean forSerialization,
String mutatorPrefix)
{
return new POJOPropertiesCollector(config, forSerialization, type, classDef, accNaming);
return new POJOPropertiesCollector(config, forSerialization, type, ac, mutatorPrefix);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ public class POJOPropertiesCollector
*/
protected final boolean _forSerialization;

/**
* @since 2.5
*/
@Deprecated
protected final boolean _stdBeanNaming;

/**
* Type of POJO for which properties are being collected.
*/
Expand All @@ -66,13 +60,6 @@ public class POJOPropertiesCollector
*/
protected final boolean _useAnnotations;

/**
* Prefix used by auto-detected mutators ("setters"): usually "set",
* but differs for builder objects ("with" by default).
*/
@Deprecated
protected final String _mutatorPrefix;

/*
/**********************************************************
/* Collected property information
Expand Down Expand Up @@ -150,35 +137,38 @@ public class POJOPropertiesCollector
* value injection.
*/
protected LinkedHashMap<Object, AnnotatedMember> _injectables;

// // // Deprecated entries to remove from 3.0

/**
* @deprecated Since 2.12
*/
@Deprecated
protected final boolean _stdBeanNaming;

/**
* @deprecated Since 2.12
*/
@Deprecated
protected String _mutatorPrefix = "set";

/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/

@Deprecated
protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization,
JavaType type, AnnotatedClass classDef, String mutatorPrefix)
{
this(config, forSerialization, type, classDef, null, mutatorPrefix);
}

/**
* @since 2.12
*/
protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization,
JavaType type, AnnotatedClass classDef, AccessorNamingStrategy accessorNaming)
{
this(config, forSerialization, type, classDef, accessorNaming, null);
}

private POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization,
JavaType type, AnnotatedClass classDef, AccessorNamingStrategy accessorNaming, String mutatorPrefix)
JavaType type, AnnotatedClass classDef,
AccessorNamingStrategy accessorNaming)
{
_config = config;
_stdBeanNaming = config.isEnabled(MapperFeature.USE_STD_BEAN_NAMING);
_forSerialization = forSerialization;
_type = type;
_classDef = classDef;
_mutatorPrefix = (mutatorPrefix == null) ? "set" : mutatorPrefix;
if (config.isAnnotationProcessingEnabled()) {
_useAnnotations = true;
_annotationIntrospector = _config.getAnnotationIntrospector();
Expand All @@ -188,8 +178,32 @@ private POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization
}
_visibilityChecker = _config.getDefaultVisibilityChecker(type.getRawClass(),
classDef);
_accessorNaming = (null != accessorNaming) ? accessorNaming :
new DefaultAccessorNamingStrategy.Provider().withSetterPrefix(mutatorPrefix).forPOJO(config, classDef);
_accessorNaming = accessorNaming;

// for backwards-compatibility only
_stdBeanNaming = config.isEnabled(MapperFeature.USE_STD_BEAN_NAMING);
}

/**
* @deprecated Since 2.12
*/
@Deprecated
protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization,
JavaType type, AnnotatedClass classDef,
String mutatorPrefix)
{
this(config, forSerialization, type, classDef,
_accessorNaming(config, classDef, mutatorPrefix));
_mutatorPrefix = mutatorPrefix;
}

private static AccessorNamingStrategy _accessorNaming(MapperConfig<?> config, AnnotatedClass classDef,
String mutatorPrefix) {
if (mutatorPrefix == null) {
mutatorPrefix = "set";
}
return new DefaultAccessorNamingStrategy.Provider()
.withSetterPrefix(mutatorPrefix).forPOJO(config, classDef);
}

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

protected void _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {

protected boolean _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
if (creatorProperties != null) {
final String intName = prop.getInternalName();
for (int i = 0, len = creatorProperties.size(); i < len; ++i) {
if (creatorProperties.get(i).getInternalName().equals(intName)) {
creatorProperties.set(i, prop);
break;
return true;
}
}
}
}

private static class MonitoredList<T> extends AbstractList<T> {
private final List<T> delegate;
private boolean modified;

public MonitoredList(List<T> delegate) {
this.delegate = delegate;
this.modified = false;
}

@Override
public T get(int index) {
return this.delegate.get(index);
}

@Override
public int size() {
return this.delegate.size();
}

public T set(int index, T element) {
this.modified = true;
return this.delegate.set(index, element);
}

public void add(int index, T element) {
this.modified = true;
this.delegate.add(index, element);
}

public T remove(int index) {
this.modified = true;
return this.delegate.remove(index);
}

public boolean isModified() {
return this.modified;
}

public static <T> MonitoredList<T> monitor(List<T> source) {
return null == source ? null : new MonitoredList<>(source);
}
return false;
}
}

0 comments on commit e01bcf9

Please sign in to comment.