@@ -135,16 +135,45 @@ public boolean hasAdapters() {
135
135
* Register a reactive type along with functions to adapt to and from a
136
136
* Reactive Streams {@link Publisher}. The function arguments assume that
137
137
* their input is neither {@code null} nor {@link Optional}.
138
+ * <p>This variant registers the new adapter after existing adapters.
139
+ * It will be matched for the exact reactive type if no earlier adapter was
140
+ * registered for the specific type, and it will be matched for assignability
141
+ * in a second pass if no earlier adapter had an assignable type before.
142
+ * @see #registerReactiveTypeOverride
143
+ * @see #getAdapter
138
144
*/
139
145
public void registerReactiveType (ReactiveTypeDescriptor descriptor ,
140
146
Function <Object , Publisher <?>> toAdapter , Function <Publisher <?>, Object > fromAdapter ) {
141
147
142
- if (reactorPresent ) {
143
- this .adapters .add (new ReactorAdapter (descriptor , toAdapter , fromAdapter ));
144
- }
145
- else {
146
- this .adapters .add (new ReactiveAdapter (descriptor , toAdapter , fromAdapter ));
147
- }
148
+ this .adapters .add (buildAdapter (descriptor , toAdapter , fromAdapter ));
149
+ }
150
+
151
+ /**
152
+ * Register a reactive type along with functions to adapt to and from a
153
+ * Reactive Streams {@link Publisher}. The function arguments assume that
154
+ * their input is neither {@code null} nor {@link Optional}.
155
+ * <p>This variant registers the new adapter first, effectively overriding
156
+ * any previously registered adapters for the same reactive type. This allows
157
+ * for overriding existing adapters, in particular default adapters.
158
+ * <p>Note that existing adapters for specific types will still match before
159
+ * an assignability match with the new adapter. In order to override all
160
+ * existing matches, a new reactive type adapter needs to be registered
161
+ * for every specific type, not relying on subtype assignability matches.
162
+ * @since 5.3.30
163
+ * @see #registerReactiveType
164
+ * @see #getAdapter
165
+ */
166
+ public void registerReactiveTypeOverride (ReactiveTypeDescriptor descriptor ,
167
+ Function <Object , Publisher <?>> toAdapter , Function <Publisher <?>, Object > fromAdapter ) {
168
+
169
+ this .adapters .add (0 , buildAdapter (descriptor , toAdapter , fromAdapter ));
170
+ }
171
+
172
+ private ReactiveAdapter buildAdapter (ReactiveTypeDescriptor descriptor ,
173
+ Function <Object , Publisher <?>> toAdapter , Function <Publisher <?>, Object > fromAdapter ) {
174
+
175
+ return (reactorPresent ? new ReactorAdapter (descriptor , toAdapter , fromAdapter ) :
176
+ new ReactiveAdapter (descriptor , toAdapter , fromAdapter ));
148
177
}
149
178
150
179
/**
0 commit comments