Skip to content

Commit 812b034

Browse files
committed
More work on #4515: start refactoring BasicDeserializerFactory
1 parent c2be01a commit 812b034

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public boolean isNonStaticInnerClass() {
109109

110110
/*
111111
/**********************************************************
112-
/* Basic API for finding creator members
112+
/* Basic API for finding Creators, related information
113113
/**********************************************************
114114
*/
115115

@@ -166,6 +166,15 @@ public boolean isNonStaticInnerClass() {
166166
*/
167167
public abstract AnnotatedConstructor findDefaultConstructor();
168168

169+
/**
170+
* Method that is replacing earlier Creator introspection access methods.
171+
*
172+
* @since 2.18
173+
*
174+
* @return Container for introspected Creator candidates, if any
175+
*/
176+
public abstract PotentialCreators getPotentialCreators();
177+
169178
/*
170179
/**********************************************************
171180
/* Basic API for finding property accessors

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ public List<AnnotatedAndMetadata<AnnotatedConstructor, JsonCreator.Mode>> getCon
340340
return result;
341341
}
342342

343+
@Override
344+
public PotentialCreators getPotentialCreators() {
345+
return _propCollector.getPotentialCreators();
346+
}
347+
343348
@Override
344349
public Object instantiateBean(boolean fixAccess) {
345350
AnnotatedConstructor ac = _classInfo.getDefaultConstructor();
@@ -363,7 +368,7 @@ public Object instantiateBean(boolean fixAccess) {
363368
+ClassUtil.exceptionMessage(t), t);
364369
}
365370
}
366-
371+
367372
/*
368373
/**********************************************************
369374
/* Simple accessors, extended

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

+25-10
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public class POJOPropertiesCollector
9191

9292
protected List<POJOPropertyBuilder> _creatorProperties;
9393

94+
/**
95+
* @since 2.18
96+
*/
97+
protected PotentialCreators _potentialCreators;
98+
9499
/**
95100
* A set of "field renamings" that have been discovered, indicating
96101
* intended renaming of other accessors: key is the implicit original
@@ -218,6 +223,14 @@ public List<BeanPropertyDefinition> getProperties() {
218223
return new ArrayList<>(props.values());
219224
}
220225

226+
// @since 2.18
227+
public PotentialCreators getPotentialCreators() {
228+
if (!_collected) {
229+
collectAll();
230+
}
231+
return _potentialCreators;
232+
}
233+
221234
public Map<Object, AnnotatedMember> getInjectables() {
222235
if (!_collected) {
223236
collectAll();
@@ -626,6 +639,8 @@ protected void _addFields(Map<String, POJOPropertyBuilder> props)
626639
// Completely rewritten in 2.18
627640
protected void _addCreators(Map<String, POJOPropertyBuilder> props)
628641
{
642+
final PotentialCreators creators = new PotentialCreators();
643+
_potentialCreators = creators;
629644
_creatorProperties = new ArrayList<>();
630645

631646
// First, resolve explicit annotations for all potential Creators
@@ -648,35 +663,35 @@ protected void _addCreators(Map<String, POJOPropertyBuilder> props)
648663
_removeDisabledCreators(constructors);
649664
_removeDisabledCreators(factories);
650665

651-
final PotentialCreators collector = new PotentialCreators();
652666
// and use annotations to find explicitly chosen Creators
653667
if (_useAnnotations) { // can't have explicit ones without Annotation introspection
654668
// Start with Constructors as they have higher precedence:
655-
_addExplicitlyAnnotatedCreators(collector, constructors, props, false);
669+
_addExplicitlyAnnotatedCreators(creators, constructors, props, false);
656670
// followed by Factory methods (lower precedence)
657-
_addExplicitlyAnnotatedCreators(collector, factories, props,
658-
collector.hasPropertiesBased());
671+
_addExplicitlyAnnotatedCreators(creators, factories, props,
672+
creators.hasPropertiesBased());
659673
}
660674

661675
// If no Explicitly annotated creators found, look
662676
// for ones with explicitly-named ({@code @JsonProperty}) parameters
663-
if (!collector.hasPropertiesBased()) {
677+
if (!creators.hasPropertiesBased()) {
664678
// only discover constructor Creators?
665-
_addCreatorsWithAnnotatedNames(collector, constructors);
679+
_addCreatorsWithAnnotatedNames(creators, constructors);
666680
}
667681

668682
// But if no annotation-based Creators found, find/use canonical Creator
669683
// (JDK 17 Record/Scala/Kotlin)
670-
if (!collector.hasPropertiesBased()) {
684+
if (!creators.hasPropertiesBased()) {
671685
// for Records:
672686
if ((canonical != null) && constructors.contains(canonical)) {
673687
constructors.remove(canonical);
674-
collector.addPropertiesBased(_config, canonical, "canonical");
688+
creators.addPropertiesBased(_config, canonical, "canonical");
675689
}
676690
}
677691

678-
// And finally add logical properties:
679-
PotentialCreator primary = collector.propertiesBased;
692+
// And finally add logical properties for the One Properties-based
693+
// creator selected (if any):
694+
PotentialCreator primary = creators.propertiesBased;
680695
if (primary != null) {
681696
_addCreatorParams(props, primary);
682697
}

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class PotentialCreators
1111
*/
1212
public PotentialCreator propertiesBased;
1313

14-
public final List<PotentialCreator> delegating = new ArrayList<>();
14+
private List<PotentialCreator> delegating;
1515

1616
public PotentialCreators()
1717
{
@@ -36,6 +36,9 @@ public void addPropertiesBased(MapperConfig<?> config, PotentialCreator ctor, St
3636

3737
public void addDelegating(PotentialCreator ctor)
3838
{
39+
if (delegating == null) {
40+
delegating = new ArrayList<>();
41+
}
3942
delegating.add(ctor);
4043
}
4144

@@ -50,6 +53,10 @@ public boolean hasPropertiesBased() {
5053
}
5154

5255
public boolean hasPropertiesBasedOrDelegating() {
53-
return (propertiesBased != null) || !delegating.isEmpty();
56+
return (propertiesBased != null) || (delegating != null && !delegating.isEmpty());
57+
}
58+
59+
public List<PotentialCreator> getDelegating() {
60+
return (delegating == null) ? Collections.emptyList() : delegating;
5461
}
5562
}

0 commit comments

Comments
 (0)