Browse Source

Polishing.

Invert types to retain check to avoid double negation.

See #4674
Original pull request: #4718
pull/4759/head
Mark Paluch 2 years ago
parent
commit
ad45069f50
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 16
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java

16
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java

@ -816,7 +816,7 @@ public class QueryMapper {
@Nullable @Nullable
public Object convertId(@Nullable Object id, Class<?> targetType) { public Object convertId(@Nullable Object id, Class<?> targetType) {
if (!SpecialTypeTreatment.INSTANCE.isConversionCandidate(id)) { if (Quirks.skipConversion(id)) {
return id; return id;
} }
@ -881,8 +881,7 @@ public class QueryMapper {
private Object applyFieldTargetTypeHintToValue(Field documentField, @Nullable Object value) { private Object applyFieldTargetTypeHintToValue(Field documentField, @Nullable Object value) {
if (value == null || documentField.getProperty() == null || !documentField.getProperty().hasExplicitWriteTarget() if (value == null || documentField.getProperty() == null || !documentField.getProperty().hasExplicitWriteTarget()
|| value instanceof Document || value instanceof DBObject || value instanceof Document || value instanceof DBObject || Quirks.skipConversion(value)) {
|| !SpecialTypeTreatment.INSTANCE.isConversionCandidate(value)) {
return value; return value;
} }
@ -1611,20 +1610,19 @@ public class QueryMapper {
} }
/* /*
* Types that must not be converted * Types that must not be converted.
*/ */
enum SpecialTypeTreatment { static class Quirks {
INSTANCE; private static final Set<Class<?>> types = Set.of(Pattern.class, BsonRegularExpression.class);
private final Set<Class<?>> types = Set.of(Pattern.class, BsonRegularExpression.class); static boolean skipConversion(@Nullable Object value) {
boolean isConversionCandidate(@Nullable Object value) {
if (value == null) { if (value == null) {
return false; return false;
} }
return !types.contains(value.getClass()); return types.contains(value.getClass());
} }
} }
} }

Loading…
Cancel
Save