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