Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: TypeManager initialization fails, if Jackson is not on class path #3149

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public DefaultTypeManager(DatabaseConfig config, BootupClasses bootupClasses) {
this.offlineMigrationGeneration = DbOffline.isGenerateMigration();
this.defaultEnumType = config.getDefaultEnumType();

ServiceLoader<ScalarJsonMapper> mappers = ServiceLoader.load(ScalarJsonMapper.class);
jsonMapper = mappers.findFirst().orElse(null);
jsonMapper = findJsonMapper();

initialiseStandard(config);
initialiseJavaTimeTypes(config);
Expand All @@ -110,6 +109,28 @@ public DefaultTypeManager(DatabaseConfig config, BootupClasses bootupClasses) {
}
}

/**
* Searches the JsonMapper and checks if markerAnnotation is on class path.
*/
private static ScalarJsonMapper findJsonMapper() {
ServiceLoader<ScalarJsonMapper> mappers = ServiceLoader.load(ScalarJsonMapper.class);
ScalarJsonMapper mapper = mappers.findFirst().orElse(null);
if (mapper != null) {
try {
if (mapper.markerAnnotation() != null) {
return mapper;
} else {
log.log(System.Logger.Level.WARNING, "Not using {0}, because no marker annotation was provided. " +
"Please check, if there is a supported json library (e.g. jackson) on your classpath", mapper.getClass().getName());
}
} catch (NoClassDefFoundError e) {
log.log(System.Logger.Level.WARNING, "Can not use {0}. An error occured: {1}. " +
"Please check, if there is a supported json library (e.g. jackson) on your classpath", mapper.getClass().getName(), e.getMessage());
}
}
return null;
}

private void loadGeoTypeBinder(DatabaseConfig config) {
GeoTypeProvider provider = config.getServiceObject(GeoTypeProvider.class);
if (provider == null) {
Expand Down