diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java index 0c4d396cd4..6ea94bab73 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java @@ -128,6 +128,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware, EnvironmentCapable { private static final String INCOMPATIBLE_TYPES = "Cannot convert %1$s of type %2$s into an instance of %3$s; Implement a custom Converter<%2$s, %3$s> and register it with the CustomConversions; Parent object was: %4$s"; + private static final String INCOMPATIBLE_MAP = "Expected map like structure but found %s"; private static final String INVALID_TYPE_TO_READ = "Expected to read Document %s into type %s but didn't find a PersistentEntity for the latter"; public static final TypeInformation BSON = TypeInformation.of(Bson.class); @@ -2392,9 +2393,8 @@ public S convert(Object source, TypeInformation if (BsonUtils.supportsBson(source)) { return (S) mapConverter.convert(context, BsonUtils.asBson(source), typeHint); } - - throw new IllegalArgumentException( - String.format("Expected map like structure but found %s", source.getClass())); + throw new MappingException( + String.format(INCOMPATIBLE_MAP, source)); } if (source instanceof DBRef dbRef) {