From bf8b85ef98541d2a6f2b0746e5e3611b2f9e7aa8 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 24 May 2011 00:41:43 +0200 Subject: [PATCH] Fixed invalid exception in looking up a type hint from DBObject. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So far the implementation of MappingMongoConverter.findTypeToBeUsed(…) threw an exception if it found a type hind but couldn't load the class. This causes issues when the class names change where the document still contains 'old' type information. Not being able to load a class should simply be considered as no type information found, thus we're returning null now. Updated Javadoc accordingly. --- .../mongodb/convert/MappingMongoConverter.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/convert/MappingMongoConverter.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/convert/MappingMongoConverter.java index 0bfef869a..7296c57d8 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/convert/MappingMongoConverter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/convert/MappingMongoConverter.java @@ -760,10 +760,13 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App } /** - * Returns the type to be used to convert the DBObject given to. - * + * Returns the type to be used to convert the DBObject given to. Will return {@literal null} if there's not type hint + * found in the {@link DBObject} or the type hint found can't be converted into a {@link Class} as the type might not + * be available. + * * @param dbObject - * @return + * @return the type to be used for converting the given {@link DBObject} into or {@literal null} if there's no type + * found. */ protected Class findTypeToBeUsed(DBObject dbObject) { Object classToBeUsed = dbObject.get(CUSTOM_TYPE_KEY); @@ -775,7 +778,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App try { return Class.forName(classToBeUsed.toString()); } catch (ClassNotFoundException e) { - throw new MappingException(e.getMessage(), e); + return null; } }