Skip to content

Commit 2932040

Browse files
committed
remove jackson 2, unify dependency approach
1 parent c45e090 commit 2932040

File tree

12 files changed

+104
-75
lines changed

12 files changed

+104
-75
lines changed

multipart-spring-graphql/pom.xml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<artifactId>multipart-spring-graphql-parent</artifactId>
1010
<groupId>name.nkonev.multipart-spring-graphql</groupId>
11-
<version>1.6.1-SNAPSHOT</version>
11+
<version>2.0.0-SNAPSHOT</version>
1212
</parent>
1313

1414
<dependencies>
@@ -26,6 +26,17 @@
2626
<artifactId>spring-boot-starter-web</artifactId>
2727
<optional>true</optional>
2828
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-restclient</artifactId>
32+
<optional>true</optional>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-webclient</artifactId>
37+
<optional>true</optional>
38+
</dependency>
39+
2940
<dependency>
3041
<groupId>org.springframework.boot</groupId>
3142
<artifactId>spring-boot-starter-test</artifactId>
@@ -41,18 +52,6 @@
4152
<artifactId>spring-security-test</artifactId>
4253
<scope>test</scope>
4354
</dependency>
44-
<dependency>
45-
<groupId>org.springframework.boot</groupId>
46-
<artifactId>spring-boot-restclient</artifactId>
47-
</dependency>
48-
<dependency>
49-
<groupId>org.springframework.boot</groupId>
50-
<artifactId>spring-boot-webclient</artifactId>
51-
</dependency>
52-
<dependency>
53-
<groupId>com.fasterxml.jackson.core</groupId>
54-
<artifactId>jackson-databind</artifactId>
55-
</dependency>
5655
</dependencies>
5756

5857
</project>

multipart-spring-graphql/src/main/java/name/nkonev/multipart/spring/graphql/server/webmvc/MultipartGraphQlHttpHandler.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22

33
import java.io.IOException;
44
import java.io.InputStream;
5-
import java.lang.reflect.Type;
65
import java.util.Arrays;
76
import java.util.List;
87
import java.util.Map;
98
import java.util.Optional;
109
import java.util.HashMap;
1110
import java.util.concurrent.ExecutionException;
1211

13-
1412
import jakarta.servlet.ServletException;
1513
import jakarta.servlet.http.Cookie;
1614
import jakarta.servlet.http.HttpServletRequest;
1715
import jakarta.servlet.http.Part;
1816
import name.nkonev.multipart.spring.graphql.server.support.MultipartVariableMapper;
1917
import org.apache.commons.logging.Log;
2018
import org.apache.commons.logging.LogFactory;
19+
import org.springframework.core.ResolvableType;
2120
import org.springframework.http.HttpCookie;
2221
import org.springframework.http.HttpHeaders;
2322
import org.springframework.http.HttpInputMessage;
24-
import org.springframework.http.converter.GenericHttpMessageConverter;
23+
import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter;
2524
import org.springframework.util.*;
2625
import org.springframework.web.multipart.MultipartFile;
2726
import org.springframework.web.multipart.MultipartHttpServletRequest;
@@ -56,13 +55,13 @@ public class MultipartGraphQlHttpHandler {
5655

5756
private final WebGraphQlHandler graphQlHandler;
5857

59-
private final GenericHttpMessageConverter genericHttpMessageConverter;
58+
private final JacksonJsonHttpMessageConverter httpMessageConverter;
6059

61-
public MultipartGraphQlHttpHandler(WebGraphQlHandler graphQlHandler, GenericHttpMessageConverter genericHttpMessageConverter) {
60+
public MultipartGraphQlHttpHandler(WebGraphQlHandler graphQlHandler, JacksonJsonHttpMessageConverter httpMessageConverter) {
6261
Assert.notNull(graphQlHandler, "WebGraphQlHandler is required");
63-
Assert.notNull(genericHttpMessageConverter, "GenericHttpMessageConverter is required");
62+
Assert.notNull(httpMessageConverter, "GenericHttpMessageConverter is required");
6463
this.graphQlHandler = graphQlHandler;
65-
this.genericHttpMessageConverter = genericHttpMessageConverter;
64+
this.httpMessageConverter = httpMessageConverter;
6665
}
6766

6867
public ServerResponse handleMultipartRequest(ServerRequest serverRequest) throws Exception {
@@ -71,7 +70,7 @@ public ServerResponse handleMultipartRequest(ServerRequest serverRequest) throws
7170
Map<String, Object> inputQuery = Optional.ofNullable(this.<Map<String, Object>>deserializePart(
7271
httpServletRequest,
7372
"operations",
74-
MAP_PARAMETERIZED_TYPE_REF.getType()
73+
ResolvableType.forType(MAP_PARAMETERIZED_TYPE_REF.getType())
7574
)).orElse(new HashMap<>());
7675

7776
final Map<String, Object> queryVariables = getFromMapOrEmpty(inputQuery, "variables");
@@ -82,7 +81,7 @@ public ServerResponse handleMultipartRequest(ServerRequest serverRequest) throws
8281
Map<String, List<String>> fileMappings = Optional.ofNullable(this.<Map<String, List<String>>>deserializePart(
8382
httpServletRequest,
8483
"map",
85-
LIST_PARAMETERIZED_TYPE_REF.getType()
84+
ResolvableType.forType(LIST_PARAMETERIZED_TYPE_REF.getType())
8685
)).orElse(new HashMap<>());
8786

8887
fileMappings.forEach((String fileKey, List<String> objectPaths) -> {
@@ -171,13 +170,13 @@ public HttpHeaders getHeaders() {
171170
}
172171
}
173172

174-
private <T> T deserializePart(HttpServletRequest httpServletRequest, String name, Type type) {
173+
private <T> T deserializePart(HttpServletRequest httpServletRequest, String name, ResolvableType type) {
175174
try {
176175
Part part = httpServletRequest.getPart(name);
177176
if (part == null) {
178177
return null;
179178
}
180-
return (T) this.genericHttpMessageConverter.read(type, null, new JsonMultipartInputMessage(part));
179+
return (T) this.httpMessageConverter.read(type, new JsonMultipartInputMessage(part), null);
181180
} catch (IOException | ServletException e) {
182181
throw new RuntimeException(e);
183182
}

multipart-spring-graphql/src/main/java/name/nkonev/multipart/springboot/graphql/server/MultipartGraphQlWebFluxAutoconfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package name.nkonev.multipart.springboot.graphql.server;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
43
import graphql.schema.GraphQLScalarType;
54
import name.nkonev.multipart.spring.graphql.coercing.webflux.UploadCoercing;
65
import name.nkonev.multipart.spring.graphql.server.webflux.MultipartGraphQlHttpHandler;
@@ -13,11 +12,12 @@
1312
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
1413
import org.springframework.graphql.server.WebGraphQlHandler;
1514
import org.springframework.http.MediaType;
16-
import org.springframework.http.codec.json.Jackson2JsonDecoder;
15+
import org.springframework.http.codec.json.JacksonJsonDecoder;
1716
import org.springframework.web.reactive.function.server.RequestPredicates;
1817
import org.springframework.web.reactive.function.server.RouterFunction;
1918
import org.springframework.web.reactive.function.server.RouterFunctions;
2019
import org.springframework.web.reactive.function.server.ServerResponse;
20+
import tools.jackson.databind.json.JsonMapper;
2121

2222
import static name.nkonev.multipart.spring.graphql.server.webflux.MultipartGraphQlHttpHandler.SUPPORTED_MEDIA_TYPES;
2323
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
@@ -42,11 +42,11 @@ public RuntimeWiringConfigurer runtimeWiringConfigurerUpload() {
4242
public RouterFunction<ServerResponse> graphQlMultipartRouterFunction(
4343
GraphQlProperties properties,
4444
WebGraphQlHandler webGraphQlHandler,
45-
ObjectMapper objectMapper
45+
JsonMapper jsonMapper
4646
) {
4747
String path = properties.getHttp().getPath();
4848
RouterFunctions.Builder builder = RouterFunctions.route();
49-
MultipartGraphQlHttpHandler graphqlMultipartHandler = new MultipartGraphQlHttpHandler(webGraphQlHandler, new Jackson2JsonDecoder(objectMapper));
49+
MultipartGraphQlHttpHandler graphqlMultipartHandler = new MultipartGraphQlHttpHandler(webGraphQlHandler, new JacksonJsonDecoder(jsonMapper));
5050
builder = builder.POST(path, RequestPredicates.contentType(MULTIPART_FORM_DATA)
5151
.and(RequestPredicates.accept(SUPPORTED_MEDIA_TYPES.toArray(new MediaType[]{}))), graphqlMultipartHandler::handleMultipartRequest);
5252
return builder.build();

multipart-spring-graphql/src/main/java/name/nkonev/multipart/springboot/graphql/server/MultipartGraphQlWebMvcAutoconfiguration.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package name.nkonev.multipart.springboot.graphql.server;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
43
import graphql.schema.GraphQLScalarType;
54
import name.nkonev.multipart.spring.graphql.coercing.webmvc.UploadCoercing;
65
import name.nkonev.multipart.spring.graphql.server.webmvc.MultipartGraphQlHttpHandler;
76
import org.springframework.boot.autoconfigure.AutoConfiguration;
8-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
97
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
108
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
119
import org.springframework.boot.graphql.autoconfigure.GraphQlProperties;
@@ -14,11 +12,12 @@
1412
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
1513
import org.springframework.graphql.server.WebGraphQlHandler;
1614
import org.springframework.http.MediaType;
17-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
15+
import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter;
1816
import org.springframework.web.servlet.function.RequestPredicates;
1917
import org.springframework.web.servlet.function.RouterFunction;
2018
import org.springframework.web.servlet.function.RouterFunctions;
2119
import org.springframework.web.servlet.function.ServerResponse;
20+
import tools.jackson.databind.json.JsonMapper;
2221

2322
import static name.nkonev.multipart.spring.graphql.server.webmvc.MultipartGraphQlHttpHandler.SUPPORTED_MEDIA_TYPES;
2423
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
@@ -43,19 +42,13 @@ public RuntimeWiringConfigurer runtimeWiringConfigurerUpload() {
4342
public RouterFunction<ServerResponse> graphQlMultipartRouterFunction(
4443
GraphQlProperties properties,
4544
WebGraphQlHandler webGraphQlHandler,
46-
ObjectMapper objectMapper
45+
JsonMapper jsonMapper
4746
) {
4847
String path = properties.getHttp().getPath();
4948
RouterFunctions.Builder builder = RouterFunctions.route();
50-
MultipartGraphQlHttpHandler graphqlMultipartHandler = new MultipartGraphQlHttpHandler(webGraphQlHandler, new MappingJackson2HttpMessageConverter(objectMapper));
49+
MultipartGraphQlHttpHandler graphqlMultipartHandler = new MultipartGraphQlHttpHandler(webGraphQlHandler, new JacksonJsonHttpMessageConverter(jsonMapper));
5150
builder = builder.POST(path, RequestPredicates.contentType(MULTIPART_FORM_DATA)
5251
.and(RequestPredicates.accept(SUPPORTED_MEDIA_TYPES.toArray(new MediaType[]{}))), graphqlMultipartHandler::handleMultipartRequest);
5352
return builder.build();
5453
}
55-
56-
@Bean
57-
@ConditionalOnMissingBean
58-
ObjectMapper jackson2ObjectMapper() {
59-
return new ObjectMapper();
60-
}
6154
}

multipart-spring-graphql/src/main/java/name/nkonev/multipart/springboot/graphql/server/SchemaAutoconfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.springframework.context.annotation.Bean;
1111
import org.springframework.context.annotation.Configuration;
1212
import org.springframework.core.io.ByteArrayResource;
13-
import org.springframework.core.io.ClassPathResource;
1413
import org.springframework.graphql.execution.GraphQlSource;
1514

1615
@ConditionalOnWebApplication

multipart-spring-graphql/src/test/java/name/nkonev/multipart/spring/graphql/client/HttpGraphQlWebClientTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import name.nkonev.multipart.spring.graphql.server.webflux.MultipartGraphQlHttpHandler;
77
import org.junit.jupiter.api.Test;
88
import org.springframework.core.io.ClassPathResource;
9-
import org.springframework.http.codec.json.Jackson2JsonDecoder;
9+
import org.springframework.http.codec.json.JacksonJsonDecoder;
1010
import org.springframework.http.codec.multipart.FilePart;
1111
import org.springframework.http.server.reactive.HttpHandler;
1212
import org.springframework.test.web.reactive.server.HttpHandlerConnector;
@@ -86,7 +86,7 @@ void shouldSendOneCollectionOfFiles() {
8686
private static class MultipartHttpBuilderSetup extends AbstractBuilderSetup {
8787

8888
public WebClient.Builder initBuilder() {
89-
MultipartGraphQlHttpHandler handler = new MultipartGraphQlHttpHandler(webGraphQlHandler(), new Jackson2JsonDecoder());
89+
MultipartGraphQlHttpHandler handler = new MultipartGraphQlHttpHandler(webGraphQlHandler(), new JacksonJsonDecoder());
9090
RouterFunction<ServerResponse> routerFunction = route().POST("/**", handler::handleMultipartRequest).build();
9191
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction, HandlerStrategies.withDefaults());
9292
HttpHandlerConnector connector = new HttpHandlerConnector(httpHandler);

multipart-spring-graphql/src/test/java/name/nkonev/multipart/spring/graphql/client/utils/MockExecutionGraphQlService.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package name.nkonev.multipart.spring.graphql.client.utils;
1818

19-
import com.fasterxml.jackson.core.JsonProcessingException;
20-
import com.fasterxml.jackson.databind.ObjectMapper;
2119
import graphql.*;
2220
import org.springframework.graphql.ExecutionGraphQlRequest;
2321
import org.springframework.graphql.ExecutionGraphQlResponse;
@@ -27,6 +25,7 @@
2725
import org.springframework.util.Assert;
2826
import org.springframework.util.ObjectUtils;
2927
import reactor.core.publisher.Mono;
28+
import tools.jackson.databind.json.JsonMapper;
3029

3130
import java.util.Arrays;
3231
import java.util.HashMap;
@@ -40,7 +39,7 @@
4039
*/
4140
public class MockExecutionGraphQlService implements ExecutionGraphQlService {
4241

43-
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
42+
private static final JsonMapper OBJECT_MAPPER = new JsonMapper();
4443

4544

4645
@Nullable
@@ -125,12 +124,7 @@ public void setResponse(String document, ExecutionResult result) {
125124

126125
@SuppressWarnings("unchecked")
127126
private Map<String, Object> decode(String json) {
128-
try {
129-
return OBJECT_MAPPER.readValue(json, Map.class);
130-
}
131-
catch (JsonProcessingException ex) {
132-
throw new IllegalStateException(ex);
133-
}
127+
return OBJECT_MAPPER.readValue(json, Map.class);
134128
}
135129

136130
@Override

multipart-spring-graphql/src/test/java/name/nkonev/multipart/spring/graphql/server/utils/GraphQlSetup.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
import org.springframework.graphql.server.WebGraphQlHandler;
3131
import org.springframework.graphql.server.WebGraphQlInterceptor;
3232
import org.springframework.graphql.server.webflux.GraphQlHttpHandler;
33-
import org.springframework.http.codec.json.Jackson2JsonDecoder;
34-
import org.springframework.http.converter.GenericHttpMessageConverter;
35-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
33+
import org.springframework.http.codec.json.JacksonJsonDecoder;
34+
import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter;
3635

3736
import java.nio.charset.StandardCharsets;
3837
import java.util.ArrayList;
@@ -55,9 +54,9 @@ public class GraphQlSetup {
5554

5655
private final List<WebGraphQlInterceptor> interceptors = new ArrayList<>();
5756

58-
private Decoder<?> jsonDecoder = new Jackson2JsonDecoder();
57+
private Decoder<?> jsonDecoder = new JacksonJsonDecoder();
5958

60-
private GenericHttpMessageConverter genericHttpMessageConverter = new MappingJackson2HttpMessageConverter();
59+
private JacksonJsonHttpMessageConverter httpMessageConverter = new JacksonJsonHttpMessageConverter();
6160

6261
private GraphQlSetup(Resource... schemaResources) {
6362
this.graphQlSourceBuilder = GraphQlSource.schemaResourceBuilder().schemaResources(schemaResources);
@@ -121,8 +120,8 @@ public GraphQlSetup jsonDecoder(Decoder<?> jsonDecoder) {
121120
return this;
122121
}
123122

124-
public GraphQlSetup genericHttpMessageConverter(GenericHttpMessageConverter genericHttpMessageConverter) {
125-
this.genericHttpMessageConverter = genericHttpMessageConverter;
123+
public GraphQlSetup genericHttpMessageConverter(JacksonJsonHttpMessageConverter httpMessageConverter) {
124+
this.httpMessageConverter = httpMessageConverter;
126125
return this;
127126
}
128127

@@ -161,7 +160,7 @@ public org.springframework.graphql.server.webmvc.GraphQlHttpHandler toHttpHandle
161160
}
162161

163162
public name.nkonev.multipart.spring.graphql.server.webmvc.MultipartGraphQlHttpHandler toHttpHandlerMultipart() {
164-
return new name.nkonev.multipart.spring.graphql.server.webmvc.MultipartGraphQlHttpHandler(toWebGraphQlHandler(), genericHttpMessageConverter);
163+
return new name.nkonev.multipart.spring.graphql.server.webmvc.MultipartGraphQlHttpHandler(toWebGraphQlHandler(), httpMessageConverter);
165164
}
166165

167166
public GraphQlHttpHandler toHttpHandlerWebFlux() {

multipart-spring-graphql/src/test/java/name/nkonev/multipart/spring/graphql/server/webflux/GraphQlHttpHandlerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.springframework.http.MediaType;
1515
import org.springframework.http.codec.EncoderHttpMessageWriter;
1616
import org.springframework.http.codec.HttpMessageWriter;
17-
import org.springframework.http.codec.json.Jackson2JsonEncoder;
17+
import org.springframework.http.codec.json.JacksonJsonEncoder;
1818
import org.springframework.http.codec.multipart.FilePart;
1919
import org.springframework.http.codec.multipart.Part;
2020
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
@@ -37,7 +37,7 @@
3737

3838
public class GraphQlHttpHandlerTests {
3939

40-
private final Jackson2JsonEncoder jackson2JsonEncoder = new Jackson2JsonEncoder();
40+
private final JacksonJsonEncoder jackson2JsonEncoder = new JacksonJsonEncoder();
4141

4242
@Test
4343
void shouldPassFile() {
@@ -167,7 +167,7 @@ private static class DefaultContext implements ServerResponse.Context {
167167

168168
@Override
169169
public List<HttpMessageWriter<?>> messageWriters() {
170-
return Collections.singletonList(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
170+
return Collections.singletonList(new EncoderHttpMessageWriter<>(new JacksonJsonEncoder()));
171171
}
172172

173173
@Override

multipart-spring-graphql/src/test/java/name/nkonev/multipart/spring/graphql/server/webmvc/GraphQlHttpHandlerTests.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
package name.nkonev.multipart.spring.graphql.server.webmvc;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
53
import graphql.schema.GraphQLScalarType;
6-
import jakarta.servlet.ServletException;
74
import name.nkonev.multipart.spring.graphql.coercing.webmvc.UploadCoercing;
85
import name.nkonev.multipart.spring.graphql.server.utils.GraphQlSetup;
96
import org.junit.jupiter.api.Test;
107
import org.springframework.core.io.ClassPathResource;
118
import org.springframework.core.io.Resource;
129
import org.springframework.http.MediaType;
1310
import org.springframework.http.converter.HttpMessageConverter;
14-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
11+
import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter;
1512
import org.springframework.mock.web.*;
1613
import org.springframework.web.multipart.MultipartFile;
1714
import org.springframework.web.servlet.function.AsyncServerResponse;
18-
import org.springframework.web.servlet.function.EntityResponse;
1915
import org.springframework.web.servlet.function.ServerRequest;
2016
import org.springframework.web.servlet.function.ServerResponse;
17+
import tools.jackson.databind.json.JsonMapper;
2118

2219
import java.io.IOException;
2320
import java.util.*;
@@ -29,9 +26,9 @@
2926
public class GraphQlHttpHandlerTests {
3027

3128
private static final List<HttpMessageConverter<?>> MESSAGE_READERS =
32-
Collections.singletonList(new MappingJackson2HttpMessageConverter());
29+
Collections.singletonList(new JacksonJsonHttpMessageConverter());
3330

34-
private final ObjectMapper objectMapper = new ObjectMapper();
31+
private final JsonMapper jsonMapper = new JsonMapper();
3532

3633
@Test
3734
void shouldPassFile() throws Exception {
@@ -132,11 +129,7 @@ private MockMultipartFile getMultipartFile(String partName, Object objectResourc
132129
}
133130

134131
private byte[] getJsonArray(Object o) {
135-
try {
136-
return objectMapper.writeValueAsBytes(o);
137-
} catch (JsonProcessingException e) {
138-
throw new RuntimeException(e);
139-
}
132+
return jsonMapper.writeValueAsBytes(o);
140133
}
141134

142135
private MockHttpServletResponse handleMultipartRequest(

0 commit comments

Comments
 (0)