@@ -115,7 +115,7 @@ protected DBRef asReference(@Nullable Object constant) {
115115 return asReference (constant , null );
116116 }
117117
118- protected DBRef asReference (Object constant , Path <?> path ) {
118+ protected DBRef asReference (Object constant , @ Nullable Path <?> path ) {
119119 return converter .toDBRef (constant , getPropertyForPotentialDbRef (path ));
120120 }
121121
@@ -135,7 +135,7 @@ protected String asDBKey(@Nullable Operation<?> expr, int index) {
135135
136136 MongoPersistentProperty property = getPropertyFor (path );
137137
138- return property .isIdProperty () ? key .replaceAll ("." + ID_KEY + "$" , "" ) : key ;
138+ return property != null && property .isIdProperty () ? key .replaceAll ("." + ID_KEY + "$" , "" ) : key ;
139139 }
140140
141141 @ Override
@@ -144,20 +144,26 @@ protected boolean isId(Path<?> arg) {
144144 return propertyFor == null ? super .isId (arg ) : propertyFor .isIdProperty ();
145145 }
146146
147+ @ Override
148+ @ Nullable
147149 protected Object convert (@ Nullable Path <?> path , @ Nullable Constant <?> constant ) {
148150
151+ if (constant == null ) {
152+ return null ;
153+ }
154+
149155 if (!isReference (path )) {
150156
151157 MongoPersistentProperty property = getPropertyFor (path );
152- if (property == null ) {
158+ if (property == null ) {
153159 return super .convert (path , constant );
154160 }
155161
156- if (property .isIdProperty ()) {
162+ if (property .isIdProperty ()) {
157163 return mapper .convertId (constant .getConstant (), property .getFieldType ());
158164 }
159165
160- if (property .hasExplicitWriteTarget ()) {
166+ if (property .hasExplicitWriteTarget ()) {
161167 return converter .convertToMongoType (constant .getConstant (), TypeInformation .of (property .getFieldType ()));
162168 }
163169
@@ -166,17 +172,19 @@ protected Object convert(@Nullable Path<?> path, @Nullable Constant<?> constant)
166172
167173 MongoPersistentProperty property = getPropertyFor (path );
168174
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+ }
172179
173- if (property .isIdProperty ()) {
180+ if (property .isIdProperty ()) {
174181
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 ());
178187 }
179- return asReference (constant .getConstant (), path .getMetadata ().getParent ());
180188 }
181189
182190 return asReference (constant .getConstant (), path );
@@ -203,7 +211,8 @@ private MongoPersistentProperty getPropertyFor(Path<?> path) {
203211 * @param path
204212 * @return
205213 */
206- private MongoPersistentProperty getPropertyForPotentialDbRef (Path <?> path ) {
214+ @ Nullable
215+ private MongoPersistentProperty getPropertyForPotentialDbRef (@ Nullable Path <?> path ) {
207216
208217 if (path == null ) {
209218 return null ;
0 commit comments