2
2
3
3
import com .alibaba .fastjson .JSONObject ;
4
4
import lombok .SneakyThrows ;
5
- import org .springframework .beans .BeanUtils ;
6
5
import org .springframework .util .LinkedMultiValueMap ;
7
6
import org .springframework .util .MultiValueMap ;
8
7
9
- import java .beans .PropertyDescriptor ;
10
8
import java .net .URLEncoder ;
11
9
import java .nio .charset .StandardCharsets ;
12
10
@@ -26,13 +24,17 @@ public static RestParamBuilder create() {
26
24
27
25
@ SneakyThrows
28
26
public static RestParamBuilder parser (Object obj ) {
29
- PropertyDescriptor [] descriptors = BeanUtils .getPropertyDescriptors (obj .getClass ());
30
27
RestParamBuilder builder = create ();
31
- for (PropertyDescriptor descriptor : descriptors ) {
32
- String name = descriptor .getName ();
33
- Object value = BeanUtils .getPropertyDescriptor (obj .getClass (), name );
34
- if (value != null ) {
35
- builder .add (name , value );
28
+ JSONObject object = (JSONObject ) JSONObject .toJSON (obj );
29
+ for (String key : object .keySet ()) {
30
+ Object value = object .getJSONObject (key );
31
+ if (value !=null ){
32
+ builder .add (key , value );
33
+ }else {
34
+ value = object .getJSONArray (key );
35
+ if (value != null ) {
36
+ builder .add (key , value );
37
+ }
36
38
}
37
39
}
38
40
return builder ;
@@ -42,17 +44,17 @@ public JSONObject toJsonRequest() {
42
44
return jsonBody ;
43
45
}
44
46
45
- public MultiValueMap <String , String > toFormRequest () {
47
+ public MultiValueMap <String , String > toFormRequest () {
46
48
return mapBody ;
47
49
}
48
50
49
51
public RestParamBuilder add (String key , Object value ) {
50
- return add (key , value ,true );
52
+ return add (key , value , true );
51
53
}
52
54
53
- public RestParamBuilder add (String key , Object value ,boolean encode ) {
55
+ public RestParamBuilder add (String key , Object value , boolean encode ) {
54
56
String stringValue = value .toString ();
55
- String encodeValue = encode ? URLEncoder .encode (stringValue , StandardCharsets .UTF_8 ): value .toString ();
57
+ String encodeValue = encode ? URLEncoder .encode (stringValue , StandardCharsets .UTF_8 ) : value .toString ();
56
58
jsonBody .put (key , value );
57
59
mapBody .add (key , encodeValue );
58
60
return this ;
0 commit comments