|
20 | 20 | import org.bson.Document; |
21 | 21 | import org.jspecify.annotations.Nullable; |
22 | 22 | import org.springframework.core.annotation.MergedAnnotation; |
| 23 | +import org.springframework.core.convert.TypeDescriptor; |
| 24 | +import org.springframework.core.convert.support.DefaultConversionService; |
23 | 25 | import org.springframework.data.mapping.model.SimpleTypeHolder; |
24 | 26 | import org.springframework.data.mongodb.repository.ReadPreference; |
25 | 27 | import org.springframework.data.mongodb.repository.aot.AggregationBlocks.AggregationCodeBlockBuilder; |
@@ -241,20 +243,16 @@ static void appendReadPreference(AotQueryMethodGenerationContext context, Builde |
241 | 243 | public static CodeBlock potentiallyWrapStreamable(MethodReturn methodReturn, CodeBlock returningIterable) { |
242 | 244 |
|
243 | 245 | Class<?> returnType = methodReturn.toClass(); |
| 246 | + |
244 | 247 | if (returnType.equals(Streamable.class)) { |
245 | 248 | return CodeBlock.of("$T.of($L)", Streamable.class, returningIterable); |
246 | 249 | } |
| 250 | + |
247 | 251 | if (ClassUtils.isAssignable(Streamable.class, returnType)) { |
248 | | - CodeBlock streamable = CodeBlock.of("$T.of($L)", Streamable.class, returningIterable); |
249 | | - if (ClassUtils.hasConstructor(returnType, Streamable.class)) { |
250 | | - return CodeBlock.of("new $T($L)", returnType, streamable); |
251 | | - } |
252 | | - if (ClassUtils.hasAtLeastOneMethodWithName(returnType, "of")) { |
253 | | - return CodeBlock.of("$T.of($L)", returnType, streamable); |
254 | | - } |
255 | | - if (ClassUtils.hasAtLeastOneMethodWithName(returnType, "valueOf")) { |
256 | | - return CodeBlock.of("$T.valueOf($L)", returnType, streamable); |
257 | | - } |
| 252 | + |
| 253 | + return CodeBlock.of( |
| 254 | + "($1T) $2T.getSharedInstance().convert($3T.of($4L), $5T.valueOf($3T.class), $5T.valueOf($1T.class))", |
| 255 | + returnType, DefaultConversionService.class, Streamable.class, returningIterable, TypeDescriptor.class); |
258 | 256 | } |
259 | 257 |
|
260 | 258 | return returningIterable; |
|
0 commit comments