Skip to content

Commit d79fb99

Browse files
committed
fix: handle non-standard field casing in MapContains queries
Modified processMapContainsQuery to support Map fields with uppercase/non-standard casing (e.g., 'Positions' instead of 'positions'). The method now tries both the standard lowercase naming convention and the original field name when resolving Map fields. This fixes repository methods like findByPositionsMapContainsCusip when the Java field uses non-standard casing to match JSON data from external sources like RIOT exports.
1 parent e2d3ce4 commit d79fb99

File tree

3 files changed

+182
-376
lines changed

3 files changed

+182
-376
lines changed

redis-om-spring/src/main/java/com/redis/om/spring/repository/query/RediSearchQuery.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,25 @@ private void processMapContainsQuery(String methodName) {
424424
String nestedFieldName = matcher.group(2);
425425
String operator = matcher.group(3);
426426

427-
// Convert to lowercase first character
427+
// Store original field name before converting
428+
String originalMapFieldName = mapFieldName;
429+
430+
// Convert to lowercase first character for standard Java naming
428431
mapFieldName = Character.toLowerCase(mapFieldName.charAt(0)) + mapFieldName.substring(1);
429432
nestedFieldName = Character.toLowerCase(nestedFieldName.charAt(0)) + nestedFieldName.substring(1);
430433

431-
// Find the Map field
434+
// Find the Map field - try both lowercase and original casing
432435
Field mapField = ReflectionUtils.findField(domainType, mapFieldName);
436+
if (mapField == null) {
437+
// Try with original casing (e.g., "Positions" instead of "positions")
438+
mapField = ReflectionUtils.findField(domainType, originalMapFieldName);
439+
if (mapField != null) {
440+
// Use the actual field name for building the query
441+
mapFieldName = originalMapFieldName;
442+
}
443+
}
444+
logger.debug(String.format("Looking for Map field '%s' (or '%s') in %s: %s", mapFieldName,
445+
originalMapFieldName, domainType.getSimpleName(), mapField != null ? "FOUND" : "NOT FOUND"));
433446
if (mapField != null && Map.class.isAssignableFrom(mapField.getType())) {
434447
// Get the Map's value type
435448
Optional<Class<?>> maybeValueType = ObjectUtils.getMapValueClass(mapField);

0 commit comments

Comments
 (0)