@@ -115,7 +115,7 @@ protected DBRef asReference(@Nullable Object constant) {
115
115
return asReference (constant , null );
116
116
}
117
117
118
- protected DBRef asReference (Object constant , Path <?> path ) {
118
+ protected DBRef asReference (Object constant , @ Nullable Path <?> path ) {
119
119
return converter .toDBRef (constant , getPropertyForPotentialDbRef (path ));
120
120
}
121
121
@@ -135,7 +135,7 @@ protected String asDBKey(@Nullable Operation<?> expr, int index) {
135
135
136
136
MongoPersistentProperty property = getPropertyFor (path );
137
137
138
- return property .isIdProperty () ? key .replaceAll ("." + ID_KEY + "$" , "" ) : key ;
138
+ return property != null && property .isIdProperty () ? key .replaceAll ("." + ID_KEY + "$" , "" ) : key ;
139
139
}
140
140
141
141
@ Override
@@ -144,20 +144,26 @@ protected boolean isId(Path<?> arg) {
144
144
return propertyFor == null ? super .isId (arg ) : propertyFor .isIdProperty ();
145
145
}
146
146
147
+ @ Override
148
+ @ Nullable
147
149
protected Object convert (@ Nullable Path <?> path , @ Nullable Constant <?> constant ) {
148
150
151
+ if (constant == null ) {
152
+ return null ;
153
+ }
154
+
149
155
if (!isReference (path )) {
150
156
151
157
MongoPersistentProperty property = getPropertyFor (path );
152
- if (property == null ) {
158
+ if (property == null ) {
153
159
return super .convert (path , constant );
154
160
}
155
161
156
- if (property .isIdProperty ()) {
162
+ if (property .isIdProperty ()) {
157
163
return mapper .convertId (constant .getConstant (), property .getFieldType ());
158
164
}
159
165
160
- if (property .hasExplicitWriteTarget ()) {
166
+ if (property .hasExplicitWriteTarget ()) {
161
167
return converter .convertToMongoType (constant .getConstant (), TypeInformation .of (property .getFieldType ()));
162
168
}
163
169
@@ -166,17 +172,19 @@ protected Object convert(@Nullable Path<?> path, @Nullable Constant<?> constant)
166
172
167
173
MongoPersistentProperty property = getPropertyFor (path );
168
174
169
- if (property .isDocumentReference ()) {
170
- return converter .toDocumentPointer (constant .getConstant (), property ).getPointer ();
171
- }
175
+ if (property != null ) {
176
+ if (property .isDocumentReference ()) {
177
+ return converter .toDocumentPointer (constant .getConstant (), property ).getPointer ();
178
+ }
172
179
173
- if (property .isIdProperty ()) {
180
+ if (property .isIdProperty ()) {
174
181
175
- MongoPersistentProperty propertyForPotentialDbRef = getPropertyForPotentialDbRef (path );
176
- if (propertyForPotentialDbRef != null && propertyForPotentialDbRef .isDocumentReference ()) {
177
- return converter .toDocumentPointer (constant .getConstant (), propertyForPotentialDbRef ).getPointer ();
182
+ MongoPersistentProperty propertyForPotentialDbRef = getPropertyForPotentialDbRef (path );
183
+ if (propertyForPotentialDbRef != null && propertyForPotentialDbRef .isDocumentReference ()) {
184
+ return converter .toDocumentPointer (constant .getConstant (), propertyForPotentialDbRef ).getPointer ();
185
+ }
186
+ return asReference (constant .getConstant (), path .getMetadata ().getParent ());
178
187
}
179
- return asReference (constant .getConstant (), path .getMetadata ().getParent ());
180
188
}
181
189
182
190
return asReference (constant .getConstant (), path );
@@ -203,7 +211,8 @@ private MongoPersistentProperty getPropertyFor(Path<?> path) {
203
211
* @param path
204
212
* @return
205
213
*/
206
- private MongoPersistentProperty getPropertyForPotentialDbRef (Path <?> path ) {
214
+ @ Nullable
215
+ private MongoPersistentProperty getPropertyForPotentialDbRef (@ Nullable Path <?> path ) {
207
216
208
217
if (path == null ) {
209
218
return null ;
0 commit comments