Skip to content

Commit ada37c0

Browse files
committed
Decode from CLR data types as well
1 parent d795a8b commit ada37c0

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/compas/data/encoders.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
from __future__ import division
44

55
import json
6+
import sys
67

78
from compas.data.exceptions import DecoderError
89

10+
# We don't do this from `compas.IPY` to avoid circular imports
11+
if 'ironpython' in sys.version.lower():
12+
try:
13+
from System.Collections.Generic import IDictionary
14+
except:
15+
IDictionary = None
16+
else:
17+
IDictionary = None
18+
919

1020
def cls_from_dtype(dtype):
1121
"""Get the class object corresponding to a COMPAS data type specification.
@@ -102,4 +112,10 @@ def object_hook(self, o):
102112
except AttributeError:
103113
raise DecoderError("The data type can't be found in the specified module: {}.".format(o['dtype']))
104114

105-
return cls.from_data(o['value'])
115+
obj_value = o['value']
116+
117+
# Kick-off from_data from a rebuilt Python dictionary instead of the C# data type
118+
if IDictionary and isinstance(o, IDictionary[str, object]):
119+
obj_value = {key: obj_value[key] for key in obj_value.Keys}
120+
121+
return cls.from_data(obj_value)

0 commit comments

Comments
 (0)