@@ -701,18 +701,28 @@ def safe_encode(x):
701
701
return pm .Literal (int (x ), pm .XSD ['integer' ])
702
702
if isinstance (x , (float ,)):
703
703
return pm .Literal (x , pm .XSD ['float' ])
704
+ if isinstance (x , dict ):
705
+ outdict = {}
706
+ for key , value in x .items ():
707
+ encoded_value = safe_encode (value )
708
+ if isinstance (encoded_value , (pm .Literal ,)):
709
+ outdict [key ] = encoded_value .json_representation ()
710
+ else :
711
+ outdict [key ] = encoded_value
712
+ return pm .Literal (json .dumps (outdict ), pm .XSD ['string' ])
713
+ if isinstance (x , list ):
714
+ outlist = []
715
+ for value in x :
716
+ encoded_value = safe_encode (value )
717
+ if isinstance (encoded_value , (pm .Literal ,)):
718
+ outlist .append (encoded_value .json_representation ())
719
+ else :
720
+ outlist .append (encoded_value )
721
+ return pm .Literal (json .dumps (outlist ), pm .XSD ['string' ])
704
722
try :
705
- if isinstance (x , dict ):
706
- outdict = {}
707
- for key , value in x .items ():
708
- outdict [key ] = safe_encode (value )
709
- return pm .Literal (json .dumps (outdict ), pm .XSD ['string' ])
710
- if isinstance (x , list ):
711
- outlist = [safe_encode (value ) for value in x ]
712
- return pm .Literal (json .dumps (outlist ), pm .XSD ['string' ])
713
- return pm .Literal (dumps (x ),
714
- nipype ['pickle' ])
715
- except TypeError :
723
+ return pm .Literal (dumps (x ), nipype ['pickle' ])
724
+ except TypeError , e :
725
+ iflogger .info (e )
716
726
return pm .Literal ("Could not encode" , pm .XSD ['string' ])
717
727
718
728
0 commit comments