22
33import com .alibaba .fastjson .JSONObject ;
44import lombok .SneakyThrows ;
5- import org .springframework .beans .BeanUtils ;
65import org .springframework .util .LinkedMultiValueMap ;
76import org .springframework .util .MultiValueMap ;
87
9- import java .beans .PropertyDescriptor ;
108import java .net .URLEncoder ;
119import java .nio .charset .StandardCharsets ;
1210
@@ -26,13 +24,17 @@ public static RestParamBuilder create() {
2624
2725 @ SneakyThrows
2826 public static RestParamBuilder parser (Object obj ) {
29- PropertyDescriptor [] descriptors = BeanUtils .getPropertyDescriptors (obj .getClass ());
3027 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+ }
3638 }
3739 }
3840 return builder ;
@@ -42,17 +44,17 @@ public JSONObject toJsonRequest() {
4244 return jsonBody ;
4345 }
4446
45- public MultiValueMap <String , String > toFormRequest () {
47+ public MultiValueMap <String , String > toFormRequest () {
4648 return mapBody ;
4749 }
4850
4951 public RestParamBuilder add (String key , Object value ) {
50- return add (key , value ,true );
52+ return add (key , value , true );
5153 }
5254
53- public RestParamBuilder add (String key , Object value ,boolean encode ) {
55+ public RestParamBuilder add (String key , Object value , boolean encode ) {
5456 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 ();
5658 jsonBody .put (key , value );
5759 mapBody .add (key , encodeValue );
5860 return this ;
0 commit comments