13
13
import com .google .gson .Gson ;
14
14
import com .google .gson .GsonBuilder ;
15
15
import lombok .RequiredArgsConstructor ;
16
- import org .apache .commons .beanutils .BeanMap ;
17
16
import org .apache .commons .lang3 .StringUtils ;
18
17
18
+ import java .beans .BeanInfo ;
19
+ import java .beans .IntrospectionException ;
20
+ import java .beans .Introspector ;
21
+ import java .beans .PropertyDescriptor ;
19
22
import java .io .IOException ;
20
23
import java .io .InputStream ;
24
+ import java .lang .reflect .InvocationTargetException ;
25
+ import java .lang .reflect .Method ;
21
26
import java .nio .charset .StandardCharsets ;
22
27
import java .security .GeneralSecurityException ;
23
28
import java .text .DateFormat ;
24
29
import java .util .Iterator ;
25
30
import java .util .Map ;
31
+ import java .util .LinkedHashMap ;
26
32
import java .util .Objects ;
27
33
import java .util .Set ;
28
34
@@ -385,7 +391,7 @@ private boolean verifyNotifySign(SignatureHeader header, String data) {
385
391
* @return 拼接好的string
386
392
*/
387
393
private String parseURLPair (Object o ) {
388
- Map <Object , Object > map = new BeanMap (o );
394
+ Map <Object , Object > map = getObjectToMap (o );
389
395
Set <Map .Entry <Object , Object >> set = map .entrySet ();
390
396
Iterator <Map .Entry <Object , Object >> it = set .iterator ();
391
397
StringBuilder sb = new StringBuilder ();
@@ -399,4 +405,27 @@ private String parseURLPair(Object o) {
399
405
return sb .deleteCharAt (sb .length () - 1 ).toString ();
400
406
}
401
407
408
+ public static Map <Object , Object > getObjectToMap (Object obj ) {
409
+ try {
410
+ Map <Object , Object > result = new LinkedHashMap <>();
411
+ final Class <? extends Object > beanClass = obj .getClass ();
412
+ final BeanInfo beanInfo = Introspector .getBeanInfo (beanClass );
413
+ final PropertyDescriptor [] propertyDescriptors = beanInfo .getPropertyDescriptors ();
414
+ if (propertyDescriptors != null ) {
415
+ for (final PropertyDescriptor propertyDescriptor : propertyDescriptors ) {
416
+ if (propertyDescriptor != null ) {
417
+ final String name = propertyDescriptor .getName ();
418
+ final Method readMethod = propertyDescriptor .getReadMethod ();
419
+ if (readMethod != null ) {
420
+ result .put (name , readMethod .invoke (obj ));
421
+ }
422
+ }
423
+ }
424
+ }
425
+ return result ;
426
+ } catch (IllegalAccessException | IntrospectionException | InvocationTargetException ignored ) {
427
+ return null ;
428
+ }
429
+ }
430
+
402
431
}
0 commit comments