Skip to content

Commit bd26e27

Browse files
committed
GH-1284 Fix json mapper (jackson/gson) discovery
Resolves #1284 Signed-off-by: Oleg Zhurakousky <[email protected]>
1 parent dec0287 commit bd26e27

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@
7777
import org.springframework.messaging.converter.MessageConverter;
7878
import org.springframework.messaging.converter.StringMessageConverter;
7979
import org.springframework.stereotype.Component;
80+
import org.springframework.util.Assert;
8081
import org.springframework.util.ClassUtils;
8182
import org.springframework.util.CollectionUtils;
8283
import org.springframework.util.InvalidMimeTypeException;
8384
import org.springframework.util.MimeType;
8485
import org.springframework.util.StringUtils;
8586

87+
8688
/**
8789
* @author Dave Syer
8890
* @author Mark Fisher
@@ -212,10 +214,10 @@ public static class JsonMapperConfiguration {
212214
public JsonMapper jsonMapper(ApplicationContext context) {
213215
String preferredMapper = context.getEnvironment().getProperty(JSON_MAPPER_PROPERTY);
214216
if (StringUtils.hasText(preferredMapper)) {
215-
if ("gson".equals(preferredMapper) && ClassUtils.isPresent("com.google.gson.Gson", null)) {
217+
if ("gson".equals(preferredMapper)) {
216218
return gson(context);
217219
}
218-
else if ("jackson".equals(preferredMapper) && ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", null)) {
220+
else if ("jackson".equals(preferredMapper)) {
219221
return jackson(context);
220222
}
221223
}
@@ -231,6 +233,8 @@ else if (ClassUtils.isPresent("com.google.gson.Gson", null)) {
231233
}
232234

233235
private JsonMapper gson(ApplicationContext context) {
236+
Assert.state(ClassUtils.isPresent("com.google.gson.Gson", ClassUtils.getDefaultClassLoader()),
237+
"Can not bootstrap Gson mapper since Gson is not on the classpath");
234238
Gson gson;
235239
try {
236240
gson = context.getBean(Gson.class);
@@ -243,6 +247,8 @@ private JsonMapper gson(ApplicationContext context) {
243247

244248
@SuppressWarnings("unchecked")
245249
private JsonMapper jackson(ApplicationContext context) {
250+
Assert.state(ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", ClassUtils.getDefaultClassLoader()),
251+
"Can not bootstrap Jackson mapper since Jackson is not on the classpath");
246252
ObjectMapper mapper;
247253
try {
248254
mapper = context.getBean(ObjectMapper.class).copy();
@@ -274,7 +280,7 @@ private JsonMapper jackson(ApplicationContext context) {
274280
return new JacksonMapper(mapper);
275281
}
276282

277-
private static String getConfigDetails(ObjectMapper mapper) {
283+
private String getConfigDetails(ObjectMapper mapper) {
278284
StringBuilder sb = new StringBuilder();
279285

280286
sb.append("Modules:\n");

0 commit comments

Comments
 (0)