15
15
*/
16
16
package org .springframework .data .web .config ;
17
17
18
- import java .util .ArrayList ;
18
+ import tools .jackson .databind .json .JsonMapper ;
19
+
19
20
import java .util .List ;
20
21
21
22
import org .jspecify .annotations .Nullable ;
22
-
23
23
import org .springframework .beans .factory .BeanClassLoaderAware ;
24
24
import org .springframework .beans .factory .ObjectFactory ;
25
25
import org .springframework .beans .factory .annotation .Qualifier ;
40
40
import org .springframework .data .web .XmlBeamHttpMessageConverter ;
41
41
import org .springframework .format .FormatterRegistry ;
42
42
import org .springframework .format .support .FormattingConversionService ;
43
- import org .springframework .http .converter .HttpMessageConverter ;
44
43
import org .springframework .http .converter .HttpMessageConverters .ServerBuilder ;
45
44
import org .springframework .util .Assert ;
46
45
import org .springframework .util .ClassUtils ;
47
46
import org .springframework .web .method .support .HandlerMethodArgumentResolver ;
48
47
import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
49
48
50
-
51
49
/**
52
50
* Configuration class to register {@link PageableHandlerMethodArgumentResolver},
53
- * {@link SortHandlerMethodArgumentResolver}, {@link OffsetScrollPositionHandlerMethodArgumentResolver}
54
- * and {@link DomainClassConverter}.
51
+ * {@link SortHandlerMethodArgumentResolver}, {@link OffsetScrollPositionHandlerMethodArgumentResolver} and
52
+ * {@link DomainClassConverter}.
55
53
*
56
54
* @since 1.6
57
55
* @author Oliver Gierke
@@ -91,7 +89,8 @@ public SpringDataWebConfiguration(ApplicationContext context,
91
89
this .sortResolverCustomizer = Lazy .of ( //
92
90
() -> context .getBeanProvider (SortHandlerMethodArgumentResolverCustomizer .class ).getIfAvailable ());
93
91
this .offsetResolverCustomizer = Lazy .of ( //
94
- () -> context .getBeanProvider (OffsetScrollPositionHandlerMethodArgumentResolverCustomizer .class ).getIfAvailable ());
92
+ () -> context .getBeanProvider (OffsetScrollPositionHandlerMethodArgumentResolverCustomizer .class )
93
+ .getIfAvailable ());
95
94
}
96
95
97
96
@ Override
@@ -155,29 +154,18 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentRes
155
154
@ Override
156
155
public void configureMessageConverters (ServerBuilder builder ) {
157
156
158
- List <HttpMessageConverter <?>> converters = new ArrayList <>();
159
- configureMessageConverters (converters );
160
-
161
- for (HttpMessageConverter <?> converter : converters ) {
162
- builder .customMessageConverter (converter );
163
- }
164
- }
165
-
166
- @ Override
167
- public void configureMessageConverters (List <HttpMessageConverter <?>> converters ) {
168
-
169
157
if (ClassUtils .isPresent ("com.jayway.jsonpath.DocumentContext" , context .getClassLoader ())) {
170
158
171
- if (ClassUtils .isPresent ("tools.jackson.databind.ObjectReader " , context .getClassLoader ())) {
159
+ if (ClassUtils .isPresent ("tools.jackson.databind.ObjectMapper " , context .getClassLoader ())) {
172
160
173
- tools .jackson .databind .ObjectMapper mapper = context .getBeanProvider (tools .jackson .databind .ObjectMapper .class )
174
- .getIfUnique (tools .jackson .databind .ObjectMapper ::new );
161
+ JsonMapper mapper = context .getBeanProvider (JsonMapper .class ).getIfUnique (JsonMapper ::new );
175
162
176
163
ProjectingJacksonHttpMessageConverter converter = new ProjectingJacksonHttpMessageConverter (mapper );
177
164
converter .setBeanFactory (context );
178
165
forwardBeanClassLoader (converter );
179
166
180
- converters .add (0 , converter );
167
+ builder .customMessageConverter (converter );
168
+
181
169
} else if (ClassUtils .isPresent ("com.fasterxml.jackson.databind.ObjectMapper" , context .getClassLoader ())) {
182
170
183
171
com .fasterxml .jackson .databind .ObjectMapper mapper = context
@@ -188,13 +176,13 @@ public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
188
176
converter .setBeanFactory (context );
189
177
forwardBeanClassLoader (converter );
190
178
191
- converters . add ( 0 , converter );
179
+ builder . customMessageConverter ( converter );
192
180
}
193
181
}
194
182
195
183
if (ClassUtils .isPresent ("org.xmlbeam.XBProjector" , context .getClassLoader ())) {
196
184
197
- converters . add ( 0 , context .getBeanProvider (XmlBeamHttpMessageConverter .class ) //
185
+ builder . customMessageConverter ( context .getBeanProvider (XmlBeamHttpMessageConverter .class ) //
198
186
.getIfAvailable (XmlBeamHttpMessageConverter ::new ));
199
187
}
200
188
}
0 commit comments