1212@ Component
1313public class ResponseTypeIntrospector {
1414
15- private static final List <String > ASYNC_WRAPPERS = List . of (
16- "reactor.core.publisher.Mono" ,
17- "reactor.core.publisher.Flux " ,
18- "java.util.concurrent.CompletionStage " ,
19- "java.util.concurrent.Future " ,
20- "org.springframework.web.context.request.async.DeferredResult " ,
21- "org.springframework.web.context.request.async.WebAsyncTask"
22- );
15+ private static final List <String > ASYNC_WRAPPERS =
16+ List . of (
17+ "reactor.core.publisher.Mono " ,
18+ "reactor.core.publisher.Flux " ,
19+ "java.util.concurrent.CompletionStage " ,
20+ "java.util.concurrent.Future " ,
21+ "org.springframework.web.context.request.async.DeferredResult" ,
22+ "org.springframework.web.context.request.async.WebAsyncTask" );
2323
24- public Optional <String > extractDataRefName (Method method ) {
25- if (method == null ) return Optional .empty ();
24+ public Optional <String > extractDataRefName (Method method ) {
25+ if (method == null ) return Optional .empty ();
2626
27- ResolvableType rt = ResolvableType .forMethodReturnType (method );
27+ ResolvableType rt = ResolvableType .forMethodReturnType (method );
2828
29- rt = unwrapIf (rt );
29+ rt = unwrapIf (rt );
3030
31- for (String wrapper : ASYNC_WRAPPERS ) {
32- rt = unwrapIf (rt , wrapper );
33- }
34-
35- Class <?> raw = rt .resolve ();
36- if (raw == null || !ServiceResponse .class .isAssignableFrom (raw )) {
37- return Optional .empty ();
38- }
31+ for (String wrapper : ASYNC_WRAPPERS ) {
32+ rt = unwrapIf (rt , wrapper );
33+ }
3934
40- if (rt .getGenerics ().length == 0 ) {
41- return Optional .empty ();
42- }
35+ Class <?> raw = rt .resolve ();
36+ if (raw == null || !ServiceResponse .class .isAssignableFrom (raw )) {
37+ return Optional .empty ();
38+ }
4339
44- Class <?> dataClass = rt .getGeneric ( 0 ). resolve ();
45- return Optional .ofNullable ( dataClass ). map ( Class :: getSimpleName );
40+ if ( rt .getGenerics (). length == 0 ) {
41+ return Optional .empty ( );
4642 }
4743
48- private ResolvableType unwrapIf (ResolvableType type ) {
49- Class <?> raw = type .resolve ();
50- if (raw != null && ResponseEntity .class .isAssignableFrom (raw )) {
51- return type .getGeneric (0 );
52- }
53- return type ;
44+ Class <?> dataClass = rt .getGeneric (0 ).resolve ();
45+ return Optional .ofNullable (dataClass ).map (Class ::getSimpleName );
46+ }
47+
48+ private ResolvableType unwrapIf (ResolvableType type ) {
49+ Class <?> raw = type .resolve ();
50+ if (raw != null && ResponseEntity .class .isAssignableFrom (raw )) {
51+ return type .getGeneric (0 );
5452 }
53+ return type ;
54+ }
5555
56- private ResolvableType unwrapIf (ResolvableType type , String wrapperClassName ) {
57- Class <?> raw = type .resolve ();
58- if (raw != null && Objects .equals (raw .getName (), wrapperClassName )) {
59- return type .getGeneric (0 );
60- }
61- return type ;
56+ private ResolvableType unwrapIf (ResolvableType type , String wrapperClassName ) {
57+ Class <?> raw = type .resolve ();
58+ if (raw != null && Objects .equals (raw .getName (), wrapperClassName )) {
59+ return type .getGeneric (0 );
6260 }
63- }
61+ return type ;
62+ }
63+ }
0 commit comments