Skip to content

Commit 6f4a785

Browse files
committed
Hacking.
1 parent 79a816e commit 6f4a785

File tree

5 files changed

+25
-39
lines changed

5 files changed

+25
-39
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<xmlbeam>1.4.26</xmlbeam>
3535
<java-module-name>spring.data.commons</java-module-name>
3636
<kotlin.api.target>1.8</kotlin.api.target>
37+
<spring-hateoas>3.0.0-GH-2357-SNAPSHOT</spring-hateoas>
3738
</properties>
3839

3940
<dependencies>

src/main/java/org/springframework/data/web/ProjectingJacksonHttpMessageConverter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import tools.jackson.core.JsonGenerator;
1919
import tools.jackson.databind.ObjectMapper;
2020
import tools.jackson.databind.ObjectReader;
21+
import tools.jackson.databind.json.JsonMapper;
2122

2223
import java.io.IOException;
2324
import java.io.InputStream;
@@ -30,7 +31,6 @@
3031
import java.util.concurrent.ConcurrentHashMap;
3132

3233
import org.jspecify.annotations.Nullable;
33-
3434
import org.springframework.beans.BeansException;
3535
import org.springframework.beans.factory.BeanClassLoaderAware;
3636
import org.springframework.beans.factory.BeanFactory;
@@ -40,7 +40,6 @@
4040
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
4141
import org.springframework.http.HttpInputMessage;
4242
import org.springframework.http.MediaType;
43-
import org.springframework.http.converter.HttpMessageConverter;
4443
import org.springframework.http.converter.HttpMessageNotReadableException;
4544
import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter;
4645
import org.springframework.util.Assert;
@@ -72,15 +71,15 @@ public class ProjectingJacksonHttpMessageConverter extends JacksonJsonHttpMessag
7271
* Creates a new {@link ProjectingJacksonHttpMessageConverter} using a default {@link ObjectMapper}.
7372
*/
7473
public ProjectingJacksonHttpMessageConverter() {
75-
this.projectionFactory = initProjectionFactory(getObjectMapper());
74+
this.projectionFactory = initProjectionFactory(getMapper());
7675
}
7776

7877
/**
7978
* Creates a new {@link ProjectingJacksonHttpMessageConverter} for the given {@link ObjectMapper}.
8079
*
8180
* @param mapper must not be {@literal null}.
8281
*/
83-
public ProjectingJacksonHttpMessageConverter(ObjectMapper mapper) {
82+
public ProjectingJacksonHttpMessageConverter(JsonMapper mapper) {
8483

8584
super(mapper);
8685

src/main/java/org/springframework/data/web/config/SpringDataJackson3Configuration.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@
2828
import org.jspecify.annotations.Nullable;
2929
import org.slf4j.Logger;
3030
import org.slf4j.LoggerFactory;
31-
3231
import org.springframework.beans.factory.annotation.Autowired;
3332
import org.springframework.context.annotation.Bean;
3433
import org.springframework.data.domain.Page;
3534
import org.springframework.data.domain.PageImpl;
36-
import org.springframework.data.geo.GeoModule;
35+
import org.springframework.data.geo.GeoJacksonModule;
3736
import org.springframework.data.web.PagedModel;
3837
import org.springframework.data.web.config.EnableSpringDataWebSupport.PageSerializationMode;
3938
import org.springframework.util.ClassUtils;
@@ -47,12 +46,11 @@
4746
*/
4847
public class SpringDataJackson3Configuration implements SpringDataJackson3Modules {
4948

50-
@Nullable
51-
@Autowired(required = false) SpringDataWebSettings settings;
49+
@Nullable @Autowired(required = false) SpringDataWebSettings settings;
5250

5351
@Bean
54-
public GeoModule jackson3GeoModule() {
55-
return new GeoModule();
52+
public GeoJacksonModule jackson3GeoModule() {
53+
return new GeoJacksonModule();
5654
}
5755

5856
@Bean

src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
package org.springframework.data.web.config;
1717

18-
import java.util.ArrayList;
18+
import tools.jackson.databind.json.JsonMapper;
19+
1920
import java.util.List;
2021

2122
import org.jspecify.annotations.Nullable;
22-
2323
import org.springframework.beans.factory.BeanClassLoaderAware;
2424
import org.springframework.beans.factory.ObjectFactory;
2525
import org.springframework.beans.factory.annotation.Qualifier;
@@ -40,18 +40,16 @@
4040
import org.springframework.data.web.XmlBeamHttpMessageConverter;
4141
import org.springframework.format.FormatterRegistry;
4242
import org.springframework.format.support.FormattingConversionService;
43-
import org.springframework.http.converter.HttpMessageConverter;
4443
import org.springframework.http.converter.HttpMessageConverters.ServerBuilder;
4544
import org.springframework.util.Assert;
4645
import org.springframework.util.ClassUtils;
4746
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
4847
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
4948

50-
5149
/**
5250
* Configuration class to register {@link PageableHandlerMethodArgumentResolver},
53-
* {@link SortHandlerMethodArgumentResolver}, {@link OffsetScrollPositionHandlerMethodArgumentResolver}
54-
* and {@link DomainClassConverter}.
51+
* {@link SortHandlerMethodArgumentResolver}, {@link OffsetScrollPositionHandlerMethodArgumentResolver} and
52+
* {@link DomainClassConverter}.
5553
*
5654
* @since 1.6
5755
* @author Oliver Gierke
@@ -91,7 +89,8 @@ public SpringDataWebConfiguration(ApplicationContext context,
9189
this.sortResolverCustomizer = Lazy.of( //
9290
() -> context.getBeanProvider(SortHandlerMethodArgumentResolverCustomizer.class).getIfAvailable());
9391
this.offsetResolverCustomizer = Lazy.of( //
94-
() -> context.getBeanProvider(OffsetScrollPositionHandlerMethodArgumentResolverCustomizer.class).getIfAvailable());
92+
() -> context.getBeanProvider(OffsetScrollPositionHandlerMethodArgumentResolverCustomizer.class)
93+
.getIfAvailable());
9594
}
9695

9796
@Override
@@ -155,29 +154,18 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentRes
155154
@Override
156155
public void configureMessageConverters(ServerBuilder builder) {
157156

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-
169157
if (ClassUtils.isPresent("com.jayway.jsonpath.DocumentContext", context.getClassLoader())) {
170158

171-
if (ClassUtils.isPresent("tools.jackson.databind.ObjectReader", context.getClassLoader())) {
159+
if (ClassUtils.isPresent("tools.jackson.databind.ObjectMapper", context.getClassLoader())) {
172160

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);
175162

176163
ProjectingJacksonHttpMessageConverter converter = new ProjectingJacksonHttpMessageConverter(mapper);
177164
converter.setBeanFactory(context);
178165
forwardBeanClassLoader(converter);
179166

180-
converters.add(0, converter);
167+
builder.customMessageConverter(converter);
168+
181169
} else if (ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", context.getClassLoader())) {
182170

183171
com.fasterxml.jackson.databind.ObjectMapper mapper = context
@@ -188,13 +176,13 @@ public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
188176
converter.setBeanFactory(context);
189177
forwardBeanClassLoader(converter);
190178

191-
converters.add(0, converter);
179+
builder.customMessageConverter(converter);
192180
}
193181
}
194182

195183
if (ClassUtils.isPresent("org.xmlbeam.XBProjector", context.getClassLoader())) {
196184

197-
converters.add(0, context.getBeanProvider(XmlBeamHttpMessageConverter.class) //
185+
builder.customMessageConverter(context.getBeanProvider(XmlBeamHttpMessageConverter.class) //
198186
.getIfAvailable(XmlBeamHttpMessageConverter::new));
199187
}
200188
}

src/test/java/org/springframework/data/web/config/SpringDataWebConfigurationIntegrationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
package org.springframework.data.web.config;
1717

1818
import static org.assertj.core.api.Assertions.*;
19+
import static org.mockito.ArgumentMatchers.*;
1920
import static org.mockito.Mockito.*;
2021

2122
import tools.jackson.databind.ObjectMapper;
23+
import tools.jackson.databind.json.JsonMapper;
2224

2325
import java.util.ArrayList;
2426
import java.util.Arrays;
@@ -27,7 +29,6 @@
2729

2830
import org.junit.jupiter.api.Test;
2931
import org.mockito.ArgumentCaptor;
30-
3132
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3233
import org.springframework.context.annotation.Bean;
3334
import org.springframework.context.annotation.Configuration;
@@ -38,7 +39,6 @@
3839
import org.springframework.http.converter.HttpMessageConverters;
3940
import org.springframework.instrument.classloading.ShadowingClassLoader;
4041
import org.springframework.util.ReflectionUtils;
41-
4242
import org.xmlbeam.XBProjector;
4343

4444
import com.jayway.jsonpath.DocumentContext;
@@ -114,7 +114,7 @@ void usesCustomObjectMapper() {
114114

115115
assertThat(captor.getAllValues()).anySatisfy(converter -> {
116116
assertThat(converter).isInstanceOfSatisfying(ProjectingJacksonHttpMessageConverter.class, __ -> {
117-
assertThat(__.getObjectMapper()).isSameAs(SomeConfiguration.MAPPER);
117+
assertThat(__.getMapper()).isSameAs(SomeConfiguration.MAPPER);
118118
});
119119
});
120120
}, SomeConfiguration.class);
@@ -152,10 +152,10 @@ private static Class<?> loadWithout(Class<?> configurationClass, Class<?>... typ
152152
@Configuration
153153
static class SomeConfiguration {
154154

155-
static ObjectMapper MAPPER = new ObjectMapper();
155+
static JsonMapper MAPPER = new JsonMapper();
156156

157157
@Bean
158-
ObjectMapper mapper() {
158+
JsonMapper mapper() {
159159
return MAPPER;
160160
}
161161
}

0 commit comments

Comments
 (0)