Fix logic error detecting gson preferences
This commit is contained in:
@@ -40,7 +40,6 @@ import org.springframework.context.support.GenericApplicationContext;
|
|||||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
@@ -122,7 +121,7 @@ public class ContextFunctionCatalogInitializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ClassUtils.isPresent("com.google.gson.Gson", null)
|
if (ClassUtils.isPresent("com.google.gson.Gson", null)
|
||||||
&& !"gson".equals(context.getEnvironment().getProperty(
|
&& "gson".equals(context.getEnvironment().getProperty(
|
||||||
ContextFunctionCatalogAutoConfiguration.PREFERRED_MAPPER_PROPERTY,
|
ContextFunctionCatalogAutoConfiguration.PREFERRED_MAPPER_PROPERTY,
|
||||||
"gson"))) {
|
"gson"))) {
|
||||||
if (context.getBeanFactory().getBeanNamesForType(Gson.class, false, false).length == 0) {
|
if (context.getBeanFactory().getBeanNamesForType(Gson.class, false, false).length == 0) {
|
||||||
@@ -213,4 +212,26 @@ public class ContextFunctionCatalogInitializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://jira.spring.io/browse/SPR-17333
|
||||||
|
static class ClassUtils {
|
||||||
|
|
||||||
|
public static boolean isPresent(String string, ClassLoader classLoader) {
|
||||||
|
if (classLoader==null) {
|
||||||
|
classLoader = ClassUtils.class.getClassLoader();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Class.forName(string, false, classLoader) != null;
|
||||||
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
try {
|
||||||
|
return Class.forName(string) != null;
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user