diff --git a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java index efc1666e..08eeac9d 100644 --- a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java +++ b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java @@ -59,6 +59,7 @@ import static org.springframework.data.aerospike.util.Utils.ctxArrToString; import static org.springframework.data.aerospike.util.Utils.getExpType; import static org.springframework.data.aerospike.util.Utils.getExpValOrFail; +import static org.springframework.data.aerospike.util.Utils.objectToBoolean; public enum FilterOperation { /** @@ -2014,7 +2015,6 @@ protected Filter geoWithinRadius(IndexCollectionType collectionType, Map qualifierMap) { - Object mapKeyPlaceholder = qualifierMap.get(MAP_KEY_PLACEHOLDER); - return mapKeyPlaceholder != null && Boolean.parseBoolean(mapKeyPlaceholder.toString()); + return objectToBoolean(qualifierMap.get(MAP_KEY_PLACEHOLDER)); } } diff --git a/src/main/java/org/springframework/data/aerospike/query/qualifier/BaseQualifierBuilder.java b/src/main/java/org/springframework/data/aerospike/query/qualifier/BaseQualifierBuilder.java index bc121039..4eb640f6 100644 --- a/src/main/java/org/springframework/data/aerospike/query/qualifier/BaseQualifierBuilder.java +++ b/src/main/java/org/springframework/data/aerospike/query/qualifier/BaseQualifierBuilder.java @@ -12,6 +12,7 @@ import static org.springframework.data.aerospike.query.qualifier.QualifierKey.PATH; import static org.springframework.data.aerospike.query.qualifier.QualifierKey.SECOND_VALUE; import static org.springframework.data.aerospike.query.qualifier.QualifierKey.VALUE; +import static org.springframework.data.aerospike.util.Utils.objectToBoolean; @SuppressWarnings("unchecked") public abstract class BaseQualifierBuilder> implements IQualifierBuilder { @@ -19,8 +20,7 @@ public abstract class BaseQualifierBuilder> im protected final Map map = new HashMap<>(); public boolean getIgnoreCase() { - Object ignoreCase = map.get(IGNORE_CASE); - return ignoreCase != null && Boolean.parseBoolean(ignoreCase.toString()); + return objectToBoolean(map.get(IGNORE_CASE)); } public FilterOperation getFilterOperation() { diff --git a/src/main/java/org/springframework/data/aerospike/util/Utils.java b/src/main/java/org/springframework/data/aerospike/util/Utils.java index 85213bcc..5d16a8ef 100644 --- a/src/main/java/org/springframework/data/aerospike/util/Utils.java +++ b/src/main/java/org/springframework/data/aerospike/util/Utils.java @@ -30,6 +30,7 @@ import org.springframework.dao.InvalidDataAccessResourceUsageException; import org.springframework.data.aerospike.query.qualifier.Qualifier; import org.springframework.data.aerospike.repository.query.CriteriaDefinition; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import java.io.File; @@ -320,4 +321,14 @@ public static void setIntFromConfig(Consumer setter, Environment enviro String value = getProperty(environment, prefix, propertyName); if (value != null) setter.accept(Integer.parseInt(value)); } + + /** + * Convert an Object to boolean. + * + * @param object Can be null + * @return The given object cast to boolean, or false if it is null + */ + public static boolean objectToBoolean(@Nullable Object object) { + return object != null && (boolean) object; + } }