Skip to content

Commit

Permalink
fix the conversion for Class<-->String
Browse files Browse the repository at this point in the history
fixes #2826
  • Loading branch information
evanchooly committed Feb 18, 2024
1 parent d50b713 commit 1e55a50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions core/src/main/java/dev/morphia/mapping/codec/Conversions.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ private static void registerStringConversions() {
throw new MappingException("Could not convert String to char: " + s);
}
});
register(Class.class, String.class, Class::getName);
register(String.class, Class.class, className -> {
try {
return Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
throw new MappingException(e.getMessage(), e);
}
});

register(String.class, Boolean.class, Boolean::parseBoolean);
register(String.class, Byte.class, Byte::parseByte);
register(String.class, Double.class, Double::parseDouble);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private Object collectIdValues(Object value) {
final Map<Object, Object> ids = new LinkedHashMap<>();
Map<Object, Object> map = (Map<Object, Object>) value;
for (Map.Entry<Object, Object> o : map.entrySet()) {
ids.put(o.getKey().toString(), collectIdValues(o.getValue()));
ids.put(o.getKey(), collectIdValues(o.getValue()));
}
return ids;
} else if (value.getClass().isArray()) {
Expand Down

0 comments on commit 1e55a50

Please sign in to comment.