Browse Source

Polishing.

Reformat code, revise nullability declarations.

See #4709
Original pull request: #4721
pull/4759/head
Mark Paluch 2 years ago
parent
commit
bbef940825
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 15
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SpringDataMongodbSerializer.java

15
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SpringDataMongodbSerializer.java

@ -115,7 +115,7 @@ class SpringDataMongodbSerializer extends MongodbDocumentSerializer {
return asReference(constant, null); return asReference(constant, null);
} }
protected DBRef asReference(Object constant, Path<?> path) { protected DBRef asReference(Object constant, @Nullable Path<?> path) {
return converter.toDBRef(constant, getPropertyForPotentialDbRef(path)); return converter.toDBRef(constant, getPropertyForPotentialDbRef(path));
} }
@ -135,7 +135,7 @@ class SpringDataMongodbSerializer extends MongodbDocumentSerializer {
MongoPersistentProperty property = getPropertyFor(path); MongoPersistentProperty property = getPropertyFor(path);
return property.isIdProperty() ? key.replaceAll("." + ID_KEY + "$", "") : key; return property != null && property.isIdProperty() ? key.replaceAll("." + ID_KEY + "$", "") : key;
} }
@Override @Override
@ -144,8 +144,14 @@ class SpringDataMongodbSerializer extends MongodbDocumentSerializer {
return propertyFor == null ? super.isId(arg) : propertyFor.isIdProperty(); return propertyFor == null ? super.isId(arg) : propertyFor.isIdProperty();
} }
@Override
@Nullable
protected Object convert(@Nullable Path<?> path, @Nullable Constant<?> constant) { protected Object convert(@Nullable Path<?> path, @Nullable Constant<?> constant) {
if (constant == null) {
return null;
}
if (!isReference(path)) { if (!isReference(path)) {
MongoPersistentProperty property = getPropertyFor(path); MongoPersistentProperty property = getPropertyFor(path);
@ -166,6 +172,7 @@ class SpringDataMongodbSerializer extends MongodbDocumentSerializer {
MongoPersistentProperty property = getPropertyFor(path); MongoPersistentProperty property = getPropertyFor(path);
if (property != null) {
if (property.isDocumentReference()) { if (property.isDocumentReference()) {
return converter.toDocumentPointer(constant.getConstant(), property).getPointer(); return converter.toDocumentPointer(constant.getConstant(), property).getPointer();
} }
@ -178,6 +185,7 @@ class SpringDataMongodbSerializer extends MongodbDocumentSerializer {
} }
return asReference(constant.getConstant(), path.getMetadata().getParent()); return asReference(constant.getConstant(), path.getMetadata().getParent());
} }
}
return asReference(constant.getConstant(), path); return asReference(constant.getConstant(), path);
} }
@ -203,7 +211,8 @@ class SpringDataMongodbSerializer extends MongodbDocumentSerializer {
* @param path * @param path
* @return * @return
*/ */
private MongoPersistentProperty getPropertyForPotentialDbRef(Path<?> path) { @Nullable
private MongoPersistentProperty getPropertyForPotentialDbRef(@Nullable Path<?> path) {
if (path == null) { if (path == null) {
return null; return null;

Loading…
Cancel
Save