Skip to content

Commit d9383dc

Browse files
committed
PR ebean-orm#3149 - FIX: TypeManager initialization fails, if Jackson is not on class path
1 parent b486471 commit d9383dc

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ public DefaultTypeManager(DatabaseConfig config, BootupClasses bootupClasses) {
9797
this.offlineMigrationGeneration = DbOffline.isGenerateMigration();
9898
this.defaultEnumType = config.getDefaultEnumType();
9999

100-
ServiceLoader<ScalarJsonMapper> mappers = ServiceLoader.load(ScalarJsonMapper.class);
101-
jsonMapper = mappers.findFirst().orElse(null);
100+
jsonMapper = findJsonMapper();
102101

103102
initialiseStandard(config);
104103
initialiseJavaTimeTypes(config);
@@ -112,6 +111,28 @@ public DefaultTypeManager(DatabaseConfig config, BootupClasses bootupClasses) {
112111
}
113112
}
114113

114+
/**
115+
* Searches the JsonMapper and checks if markerAnnotation is on class path.
116+
*/
117+
private static ScalarJsonMapper findJsonMapper() {
118+
ServiceLoader<ScalarJsonMapper> mappers = ServiceLoader.load(ScalarJsonMapper.class);
119+
ScalarJsonMapper mapper = mappers.findFirst().orElse(null);
120+
if (mapper != null) {
121+
try {
122+
if (mapper.markerAnnotation() != null) {
123+
return mapper;
124+
} else {
125+
log.log(System.Logger.Level.WARNING, "Not using {0}, because no marker annotation was provided. " +
126+
"Please check, if there is a supported json library (e.g. jackson) on your classpath", mapper.getClass().getName());
127+
}
128+
} catch (NoClassDefFoundError e) {
129+
log.log(System.Logger.Level.WARNING, "Can not use {0}. An error occured: {1}. " +
130+
"Please check, if there is a supported json library (e.g. jackson) on your classpath", mapper.getClass().getName(), e.getMessage());
131+
}
132+
}
133+
return null;
134+
}
135+
115136
private void loadGeoTypeBinder(DatabaseConfig config) {
116137
GeoTypeProvider provider = config.getServiceObject(GeoTypeProvider.class);
117138
if (provider == null) {

0 commit comments

Comments
 (0)