@@ -371,9 +371,14 @@ def serialize_json(request: dataclass) -> str:
371371def dict_to_dataclass (orig : dict [str , any ], dataclass_type : str ):
372372 cast_type = str (dataclass_type ).replace (
373373 "typing.Optional[" , "" ).replace ("]" , "" )
374- cast_module = cast_type .split ("." )[:- 1 ]
374+
375+ cast_modules = cast_type .split ("." )[:- 1 ]
376+ if cast_modules [0 ] == "typing" :
377+ # This is a built-in type, not a data_class
378+ return orig
379+
375380 module = None
376- for m in cast_module :
381+ for m in cast_modules :
377382 if not module :
378383 module = __import__ (m )
379384 else :
@@ -579,7 +584,7 @@ def serialize_form(data: dataclass, meta_string: str) -> dict[str, any]:
579584
580585
581586def _populate_form (field_name : str , explode : boolean , obj : any , get_field_name_func : Callable ) -> dict [str , list [str ]]:
582- params : dict [str , list [str ]] = {}
587+ params : dict [str , str | list [str ]] = {}
583588
584589 if is_dataclass (obj ):
585590 items = []
@@ -602,12 +607,7 @@ def _populate_form(field_name: str, explode: boolean, obj: any, get_field_name_f
602607 items = []
603608 for key , value in obj .items ():
604609 if explode :
605- # Python uses True and False instead of true and false for booleans;
606- # This json encodes the values _only_ if the value is a boolean.
607- if value is True or value is False :
608- params [key ] = json .dumps (value )
609- else :
610- params [key ] = value
610+ _populate_simple_param (params , key , value )
611611 else :
612612 items .append (f'{ key } ,{ value } ' )
613613
@@ -627,11 +627,20 @@ def _populate_form(field_name: str, explode: boolean, obj: any, get_field_name_f
627627 if len (items ) > 0 :
628628 params [field_name ] = [',' .join ([str (item ) for item in items ])]
629629 else :
630- params [ field_name ] = obj
630+ _populate_simple_param ( params , field_name , obj )
631631
632632 return params
633633
634634
635+ def _populate_simple_param (params : dict [str , str | list [str ]], field_name : str , value : any ):
636+ # Python uses True and False instead of true and false for booleans;
637+ # This json encodes the values _only_ if the value is a boolean.
638+ if value is True or value is False :
639+ params [field_name ] = json .dumps (value )
640+ else :
641+ params [field_name ] = value
642+
643+
635644def _serialize_header (explode : boolean , obj : any ) -> str :
636645 if is_dataclass (obj ):
637646 items = []
@@ -675,11 +684,8 @@ def _serialize_header(explode: boolean, obj: any) -> str:
675684
676685
677686def unmarshal_json (data , t ):
678- Unmarhsal = make_dataclass ('Unmarhsal' , [('res' , t )],
679- bases = (DataClassJsonMixin ,))
680687 d = json .loads (data )
681- out = Unmarhsal .from_dict ({"res" : d })
682- return out .res
688+ return dict_to_dataclass (d , t )
683689
684690
685691def marshal_json (c ):
0 commit comments