21
21
package org .springdoc .data .rest .customisers ;
22
22
23
23
import java .lang .reflect .Field ;
24
- import java .lang .reflect .Modifier ;
25
24
import java .lang .reflect .Type ;
26
25
import java .util .ArrayList ;
27
26
import java .util .Arrays ;
40
39
import io .swagger .v3 .oas .models .media .Schema ;
41
40
import io .swagger .v3 .oas .models .parameters .Parameter ;
42
41
import org .apache .commons .lang3 .StringUtils ;
42
+ import org .apache .commons .lang3 .reflect .FieldUtils ;
43
43
import org .slf4j .Logger ;
44
44
import org .slf4j .LoggerFactory ;
45
45
import org .springdoc .core .customizers .OperationCustomizer ;
@@ -63,8 +63,6 @@ public class QuerydslPredicateOperationCustomizer implements OperationCustomizer
63
63
64
64
private static final Logger LOGGER = LoggerFactory .getLogger (QuerydslPredicateOperationCustomizer .class );
65
65
66
- private static final String ACCESS_EXCEPTION_OCCURRED = "NoSuchFieldException or IllegalAccessException occurred : {}" ;
67
-
68
66
private QuerydslBindingsFactory querydslBindingsFactory ;
69
67
70
68
public QuerydslPredicateOperationCustomizer (QuerydslBindingsFactory querydslBindingsFactory ) {
@@ -129,28 +127,22 @@ private QuerydslBindings extractQdslBindings(QuerydslPredicate predicate) {
129
127
130
128
private Set <String > getFieldValues (QuerydslBindings instance , String fieldName ) {
131
129
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 );
136
131
return (Set <String >) field .get (instance );
137
132
}
138
- catch (NoSuchFieldException | IllegalAccessException e ) {
139
- LOGGER .warn (ACCESS_EXCEPTION_OCCURRED , e .getMessage ());
133
+ catch (IllegalAccessException e ) {
134
+ LOGGER .warn (e .getMessage ());
140
135
}
141
136
return Collections .emptySet ();
142
137
}
143
138
144
139
private Map <String , Object > getPathSpec (QuerydslBindings instance , String fieldName ) {
145
140
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 );
150
142
return (Map <String , Object >) field .get (instance );
151
143
}
152
- catch (NoSuchFieldException | IllegalAccessException e ) {
153
- LOGGER .warn (ACCESS_EXCEPTION_OCCURRED , e .getMessage ());
144
+ catch (IllegalAccessException e ) {
145
+ LOGGER .warn (e .getMessage ());
154
146
}
155
147
return Collections .emptyMap ();
156
148
}
@@ -160,14 +152,11 @@ private Optional<Path<?>> getPathFromPathSpec(Object instance) {
160
152
if (instance == null ) {
161
153
return Optional .empty ();
162
154
}
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 );
167
156
return (Optional <Path <?>>) field .get (instance );
168
157
}
169
- catch (NoSuchFieldException | IllegalAccessException e ) {
170
- LOGGER .warn (ACCESS_EXCEPTION_OCCURRED , e .getMessage ());
158
+ catch (IllegalAccessException e ) {
159
+ LOGGER .warn (e .getMessage ());
171
160
}
172
161
return Optional .empty ();
173
162
}
0 commit comments