@@ -105,16 +105,45 @@ public ReactiveAdapterRegistry() {
105
105
* Register a reactive type along with functions to adapt to and from a
106
106
* Reactive Streams {@link Publisher}. The function arguments assume that
107
107
* their input is neither {@code null} nor {@link Optional}.
108
+ * <p>This variant registers the new adapter after existing adapters.
109
+ * It will be matched for the exact reactive type if no earlier adapter was
110
+ * registered for the specific type, and it will be matched for assignability
111
+ * in a second pass if no earlier adapter had an assignable type before.
112
+ * @see #registerReactiveTypeOverride
113
+ * @see #getAdapter
108
114
*/
109
115
public void registerReactiveType (ReactiveTypeDescriptor descriptor ,
110
116
Function <Object , Publisher <?>> toAdapter , Function <Publisher <?>, Object > fromAdapter ) {
111
117
112
- if (reactorPresent ) {
113
- this .adapters .add (new ReactorAdapter (descriptor , toAdapter , fromAdapter ));
114
- }
115
- else {
116
- this .adapters .add (new ReactiveAdapter (descriptor , toAdapter , fromAdapter ));
117
- }
118
+ this .adapters .add (buildAdapter (descriptor , toAdapter , fromAdapter ));
119
+ }
120
+
121
+ /**
122
+ * Register a reactive type along with functions to adapt to and from a
123
+ * Reactive Streams {@link Publisher}. The function arguments assume that
124
+ * their input is neither {@code null} nor {@link Optional}.
125
+ * <p>This variant registers the new adapter first, effectively overriding
126
+ * any previously registered adapters for the same reactive type. This allows
127
+ * for overriding existing adapters, in particular default adapters.
128
+ * <p>Note that existing adapters for specific types will still match before
129
+ * an assignability match with the new adapter. In order to override all
130
+ * existing matches, a new reactive type adapter needs to be registered
131
+ * for every specific type, not relying on subtype assignability matches.
132
+ * @since 5.3.30
133
+ * @see #registerReactiveType
134
+ * @see #getAdapter
135
+ */
136
+ public void registerReactiveTypeOverride (ReactiveTypeDescriptor descriptor ,
137
+ Function <Object , Publisher <?>> toAdapter , Function <Publisher <?>, Object > fromAdapter ) {
138
+
139
+ this .adapters .add (0 , buildAdapter (descriptor , toAdapter , fromAdapter ));
140
+ }
141
+
142
+ private ReactiveAdapter buildAdapter (ReactiveTypeDescriptor descriptor ,
143
+ Function <Object , Publisher <?>> toAdapter , Function <Publisher <?>, Object > fromAdapter ) {
144
+
145
+ return (reactorPresent ? new ReactorAdapter (descriptor , toAdapter , fromAdapter ) :
146
+ new ReactiveAdapter (descriptor , toAdapter , fromAdapter ));
118
147
}
119
148
120
149
/**
0 commit comments