@@ -47,31 +47,33 @@ public <T> ExecutableUpdate<T> update(Class<T> domainType) {
4747
4848		Assert .notNull (domainType , "DomainType must not be null" );
4949
50- 		return  new  ExecutableUpdateSupport <>(template , domainType , ALL_QUERY , null , null , null , null , null , domainType );
50+ 		return  new  ExecutableUpdateSupport <>(template , domainType , ALL_QUERY , null , null , null , null , null , domainType ,  QueryResultConverter . entity () );
5151	}
5252
5353	/** 
5454	 * @author Christoph Strobl 
5555	 * @since 2.0 
5656	 */ 
5757	@ SuppressWarnings ("rawtypes" )
58- 	static  class  ExecutableUpdateSupport <T >
58+ 	static  class  ExecutableUpdateSupport <S ,  T >
5959			implements  ExecutableUpdate <T >, UpdateWithCollection <T >, UpdateWithQuery <T >, TerminatingUpdate <T >,
6060			FindAndReplaceWithOptions <T >, TerminatingFindAndReplace <T >, FindAndReplaceWithProjection <T > {
6161
6262		private  final  MongoTemplate  template ;
63- 		private  final  Class  domainType ;
63+ 		private  final  Class <?>  domainType ;
6464		private  final  Query  query ;
6565		@ Nullable  private  final  UpdateDefinition  update ;
6666		@ Nullable  private  final  String  collection ;
6767		@ Nullable  private  final  FindAndModifyOptions  findAndModifyOptions ;
6868		@ Nullable  private  final  FindAndReplaceOptions  findAndReplaceOptions ;
6969		@ Nullable  private  final  Object  replacement ;
70- 		private  final  Class <T > targetType ;
70+ 		private  final  QueryResultConverter <? super  S , ? extends  T > resultConverter ;
71+ 		private  final  Class <S > targetType ;
7172
72- 		ExecutableUpdateSupport (MongoTemplate  template , Class  domainType , Query  query , @ Nullable  UpdateDefinition  update ,
73+ 		ExecutableUpdateSupport (MongoTemplate  template , Class <?>  domainType , Query  query , @ Nullable  UpdateDefinition  update ,
7374				@ Nullable  String  collection , @ Nullable  FindAndModifyOptions  findAndModifyOptions ,
74- 				@ Nullable  FindAndReplaceOptions  findAndReplaceOptions , @ Nullable  Object  replacement , Class <T > targetType ) {
75+ 				@ Nullable  FindAndReplaceOptions  findAndReplaceOptions , @ Nullable  Object  replacement , Class <S > targetType ,
76+ 			QueryResultConverter <? super  S , ? extends  T > resultConverter ) {
7577
7678			this .template  = template ;
7779			this .domainType  = domainType ;
@@ -82,6 +84,7 @@ static class ExecutableUpdateSupport<T>
8284			this .findAndReplaceOptions  = findAndReplaceOptions ;
8385			this .replacement  = replacement ;
8486			this .targetType  = targetType ;
87+ 			this .resultConverter  = resultConverter ;
8588		}
8689
8790		@ Override 
@@ -91,7 +94,7 @@ public TerminatingUpdate<T> apply(UpdateDefinition update) {
9194			Assert .notNull (update , "Update must not be null" );
9295
9396			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
94- 					findAndReplaceOptions , replacement , targetType );
97+ 					findAndReplaceOptions , replacement , targetType ,  resultConverter );
9598		}
9699
97100		@ Override 
@@ -101,7 +104,7 @@ public UpdateWithQuery<T> inCollection(String collection) {
101104			Assert .hasText (collection , "Collection must not be null nor empty" );
102105
103106			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
104- 					findAndReplaceOptions , replacement , targetType );
107+ 					findAndReplaceOptions , replacement , targetType ,  resultConverter );
105108		}
106109
107110		@ Override 
@@ -111,7 +114,7 @@ public TerminatingFindAndModify<T> withOptions(FindAndModifyOptions options) {
111114			Assert .notNull (options , "Options must not be null" );
112115
113116			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , options ,
114- 					findAndReplaceOptions , replacement , targetType );
117+ 					findAndReplaceOptions , replacement , targetType ,  resultConverter );
115118		}
116119
117120		@ Override 
@@ -121,7 +124,7 @@ public FindAndReplaceWithProjection<T> replaceWith(T replacement) {
121124			Assert .notNull (replacement , "Replacement must not be null" );
122125
123126			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
124- 					findAndReplaceOptions , replacement , targetType );
127+ 					findAndReplaceOptions , replacement , targetType ,  resultConverter );
125128		}
126129
127130		@ Override 
@@ -131,7 +134,7 @@ public FindAndReplaceWithProjection<T> withOptions(FindAndReplaceOptions options
131134			Assert .notNull (options , "Options must not be null" );
132135
133136			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
134- 					options , replacement , targetType );
137+ 					options , replacement , targetType ,  resultConverter );
135138		}
136139
137140		@ Override 
@@ -143,7 +146,7 @@ public TerminatingReplace withOptions(ReplaceOptions options) {
143146				target .upsert ();
144147			}
145148			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
146- 					target , replacement , targetType );
149+ 					target , replacement , targetType ,  resultConverter );
147150		}
148151
149152		@ Override 
@@ -153,7 +156,7 @@ public UpdateWithUpdate<T> matching(Query query) {
153156			Assert .notNull (query , "Query must not be null" );
154157
155158			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
156- 					findAndReplaceOptions , replacement , targetType );
159+ 					findAndReplaceOptions , replacement , targetType ,  resultConverter );
157160		}
158161
159162		@ Override 
@@ -163,7 +166,7 @@ public <R> FindAndReplaceWithOptions<R> as(Class<R> resultType) {
163166			Assert .notNull (resultType , "ResultType must not be null" );
164167
165168			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
166- 					findAndReplaceOptions , replacement , resultType );
169+ 					findAndReplaceOptions , replacement , resultType ,  QueryResultConverter . entity () );
167170		}
168171
169172		@ Override 
@@ -181,22 +184,35 @@ public UpdateResult upsert() {
181184			return  doUpdate (true , true );
182185		}
183186
187+ 		@ Override 
188+ 		public  <R > TerminatingFindAndModify <R > map (QueryResultConverter <? super  T , ? extends  R > converter ) {
189+ 
190+ 			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
191+ 				findAndReplaceOptions , replacement , targetType , this .resultConverter .andThen (converter ));
192+ 		}
193+ 
194+ 		@ Override 
195+ 		public  <R > TerminatingFindAndReplace <R > mapResult (QueryResultConverter <? super  T , ? extends  R > converter ) {
196+ 			return  new  ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
197+ 				findAndReplaceOptions , replacement , targetType , this .resultConverter .andThen (converter ));
198+ 		}
199+ 
184200		@ Override 
185201		@ SuppressWarnings ("NullAway" )
186202		public  @ Nullable  T  findAndModifyValue () {
187203
188204			return  template .findAndModify (query , update ,
189205					findAndModifyOptions  != null  ? findAndModifyOptions  : new  FindAndModifyOptions (), targetType ,
190- 					getCollectionName ());
206+ 					getCollectionName (),  resultConverter );
191207		}
192208
193209		@ Override 
194210		@ SuppressWarnings ({ "unchecked" , "NullAway"  })
195211		public  @ Nullable  T  findAndReplaceValue () {
196212
197213			return  (T ) template .findAndReplace (query , replacement ,
198- 					findAndReplaceOptions  != null  ? findAndReplaceOptions  : FindAndReplaceOptions .empty (), domainType ,
199- 					getCollectionName (), targetType );
214+ 					findAndReplaceOptions  != null  ? findAndReplaceOptions  : FindAndReplaceOptions .empty (), ( Class )  domainType ,
215+ 					getCollectionName (), targetType , ( QueryResultConverter )  resultConverter );
200216		}
201217
202218		@ Override 
0 commit comments