2121package org .springdoc .data .rest .customisers ;
2222
2323import java .lang .reflect .Field ;
24- import java .lang .reflect .Modifier ;
2524import java .lang .reflect .Type ;
2625import java .util .ArrayList ;
2726import java .util .Arrays ;
4039import io .swagger .v3 .oas .models .media .Schema ;
4140import io .swagger .v3 .oas .models .parameters .Parameter ;
4241import org .apache .commons .lang3 .StringUtils ;
42+ import org .apache .commons .lang3 .reflect .FieldUtils ;
4343import org .slf4j .Logger ;
4444import org .slf4j .LoggerFactory ;
4545import org .springdoc .core .customizers .OperationCustomizer ;
@@ -63,8 +63,6 @@ public class QuerydslPredicateOperationCustomizer implements OperationCustomizer
6363
6464 private static final Logger LOGGER = LoggerFactory .getLogger (QuerydslPredicateOperationCustomizer .class );
6565
66- private static final String ACCESS_EXCEPTION_OCCURRED = "NoSuchFieldException or IllegalAccessException occurred : {}" ;
67-
6866 private QuerydslBindingsFactory querydslBindingsFactory ;
6967
7068 public QuerydslPredicateOperationCustomizer (QuerydslBindingsFactory querydslBindingsFactory ) {
@@ -129,28 +127,22 @@ private QuerydslBindings extractQdslBindings(QuerydslPredicate predicate) {
129127
130128 private Set <String > getFieldValues (QuerydslBindings instance , String fieldName ) {
131129 try {
132- Field field = instance .getClass ().getDeclaredField (fieldName );
133- if (Modifier .isPrivate (field .getModifiers ())) {
134- field .setAccessible (true );
135- }
130+ Field field = FieldUtils .getDeclaredField (instance .getClass (),fieldName ,true );
136131 return (Set <String >) field .get (instance );
137132 }
138- catch (NoSuchFieldException | IllegalAccessException e ) {
139- LOGGER .warn (ACCESS_EXCEPTION_OCCURRED , e .getMessage ());
133+ catch (IllegalAccessException e ) {
134+ LOGGER .warn (e .getMessage ());
140135 }
141136 return Collections .emptySet ();
142137 }
143138
144139 private Map <String , Object > getPathSpec (QuerydslBindings instance , String fieldName ) {
145140 try {
146- Field field = instance .getClass ().getDeclaredField (fieldName );
147- if (Modifier .isPrivate (field .getModifiers ())) {
148- field .setAccessible (true );
149- }
141+ Field field = FieldUtils .getDeclaredField (instance .getClass (),fieldName ,true );
150142 return (Map <String , Object >) field .get (instance );
151143 }
152- catch (NoSuchFieldException | IllegalAccessException e ) {
153- LOGGER .warn (ACCESS_EXCEPTION_OCCURRED , e .getMessage ());
144+ catch (IllegalAccessException e ) {
145+ LOGGER .warn (e .getMessage ());
154146 }
155147 return Collections .emptyMap ();
156148 }
@@ -160,14 +152,11 @@ private Optional<Path<?>> getPathFromPathSpec(Object instance) {
160152 if (instance == null ) {
161153 return Optional .empty ();
162154 }
163- Field field = instance .getClass ().getDeclaredField ("path" );
164- if (Modifier .isPrivate (field .getModifiers ())) {
165- field .setAccessible (true );
166- }
155+ Field field = FieldUtils .getDeclaredField (instance .getClass (),"path" ,true );
167156 return (Optional <Path <?>>) field .get (instance );
168157 }
169- catch (NoSuchFieldException | IllegalAccessException e ) {
170- LOGGER .warn (ACCESS_EXCEPTION_OCCURRED , e .getMessage ());
158+ catch (IllegalAccessException e ) {
159+ LOGGER .warn (e .getMessage ());
171160 }
172161 return Optional .empty ();
173162 }
0 commit comments