Skip to content

Commit 3d81f39

Browse files
Use conversion service
1 parent ef01847 commit 3d81f39

File tree

1 file changed

+8
-10
lines changed
  • spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot

1 file changed

+8
-10
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/MongoCodeBlocks.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.bson.Document;
2121
import org.jspecify.annotations.Nullable;
2222
import org.springframework.core.annotation.MergedAnnotation;
23+
import org.springframework.core.convert.TypeDescriptor;
24+
import org.springframework.core.convert.support.DefaultConversionService;
2325
import org.springframework.data.mapping.model.SimpleTypeHolder;
2426
import org.springframework.data.mongodb.repository.ReadPreference;
2527
import org.springframework.data.mongodb.repository.aot.AggregationBlocks.AggregationCodeBlockBuilder;
@@ -241,20 +243,16 @@ static void appendReadPreference(AotQueryMethodGenerationContext context, Builde
241243
public static CodeBlock potentiallyWrapStreamable(MethodReturn methodReturn, CodeBlock returningIterable) {
242244

243245
Class<?> returnType = methodReturn.toClass();
246+
244247
if (returnType.equals(Streamable.class)) {
245248
return CodeBlock.of("$T.of($L)", Streamable.class, returningIterable);
246249
}
250+
247251
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);
258256
}
259257

260258
return returningIterable;

0 commit comments

Comments
 (0)