1- import inspect
2- from deprecation import deprecated
3- import json as json_builtin
1+ import json
42from typing import Dict , Any , Type
53
64from gemd .entity .dict_serializable import DictSerializable
@@ -54,7 +52,7 @@ def dumps(self, obj, **kwargs) -> str:
5452 additional = flatten (res , self .scope )
5553 res = substitute_links (res )
5654 res ["context" ] = additional
57- return json_builtin .dumps (res , cls = GEMDEncoder , sort_keys = True , ** kwargs )
55+ return json .dumps (res , cls = GEMDEncoder , sort_keys = True , ** kwargs )
5856
5957 def loads (self , json_str : str , ** kwargs ):
6058 """
@@ -79,7 +77,7 @@ def loads(self, json_str: str, **kwargs):
7977 index = {}
8078 clazz_index = DictSerializable .class_mapping
8179 clazz_index .update (self ._clazz_index )
82- raw = json_builtin .loads (
80+ raw = json .loads (
8381 json_str ,
8482 object_hook = lambda x : self ._load_and_index (x ,
8583 index ,
@@ -163,7 +161,7 @@ def raw_dumps(self, obj, **kwargs):
163161 A serialized string of `obj`, which could be nested
164162
165163 """
166- return json_builtin .dumps (obj , cls = GEMDEncoder , sort_keys = True , ** kwargs )
164+ return json .dumps (obj , cls = GEMDEncoder , sort_keys = True , ** kwargs )
167165
168166 def thin_dumps (self , obj , ** kwargs ):
169167 """
@@ -184,7 +182,7 @@ def thin_dumps(self, obj, **kwargs):
184182 """
185183 set_uuids (obj , self .scope )
186184 res = substitute_links (obj )
187- return json_builtin .dumps (res , cls = GEMDEncoder , sort_keys = True , ** kwargs )
185+ return json .dumps (res , cls = GEMDEncoder , sort_keys = True , ** kwargs )
188186
189187 def raw_loads (self , json_str , ** kwargs ):
190188 """
@@ -208,41 +206,11 @@ def raw_loads(self, json_str, **kwargs):
208206 index = {}
209207 clazz_index = DictSerializable .class_mapping
210208 clazz_index .update (self ._clazz_index )
211- return json_builtin .loads (
209+ return json .loads (
212210 json_str ,
213211 object_hook = lambda x : self ._load_and_index (x , index , clazz_index = clazz_index ),
214212 ** kwargs )
215213
216- @deprecated (deprecated_in = "1.13.0" , removed_in = "2.0.0" ,
217- details = "Classes are now automatically registered when extending BaseEntity" )
218- def register_classes (self , classes ):
219- """
220- Register additional classes to the custom deserialization object hook.
221-
222- This allows for additional DictSerializable subclasses to be registered to the class index
223- that is used to decode the type strings. Existing keys are overwritten, allowing classes
224- in the gemd package to be subclassed and overridden in the class index by their
225- subclass.
226-
227- Parameters
228- ----------
229- classes: Dict[str, type]
230- a dict mapping the type string to the class
231-
232- """
233- if not isinstance (classes , dict ):
234- raise ValueError ("Must be given a dict from str -> class" )
235- non_string_keys = [x for x in classes .keys () if not isinstance (x , str )]
236- if len (non_string_keys ) > 0 :
237- raise ValueError (
238- "The keys must be strings, but got {} as keys" .format (non_string_keys ))
239- non_class_values = [x for x in classes .values () if not inspect .isclass (x )]
240- if len (non_class_values ) > 0 :
241- raise ValueError (
242- "The values must be classes, but got {} as values" .format (non_class_values ))
243-
244- self ._clazz_index .update (classes )
245-
246214 @staticmethod
247215 def _load_and_index (
248216 d : Dict [str , Any ],
0 commit comments