webapp/api/misc/dict2instance.py
def unsafe_deserialize(cls, json_obj: dict):
        """Deserialize the object on the data and check every possible errors in the json_obj"""
        if not isinstance(json_obj, dict):
            raise cls.DeserializeErrorClass(f"Invalid data. Expecting a map in {cls.__name__}")

        extra_keys = [key for key in json_obj.keys() if key not in cls.class_properties]
        if len(extra_keys) > 0:
            raise cls.DeserializeErrorClass(
                f'Having extra properties: [{",".join(extra_keys)}] in {cls.__name__}')

        try:
            props = {}
            for prop, DeSerClass in cls.class_properties.items():
                if prop not in json_obj and prop in cls.class_property_default_values:
                    val = cls.class_property_default_values[prop]
                else:
                    val = cls.check_deser_value(prop, DeSerClass.unsafe_deserialize(json_obj[prop]))

                props[cls.class_rename_props.get(prop, prop)] = val

            # noinspection PyArgumentList
            instance = cls(**props)
            cls.post_deserialize(instance)
            return instance
        except KeyError as e:
            raise cls.DeserializeErrorClass(f"Missing property: {e} in {cls.__name__}")
Deserialize the object on the data and check every possible errors in the json_obj
Deserialize the object on the data and check every possible errors in the json_obj
Deserialize the object on the data and check every possible errors in the json_obj
def unsafe_deserialize(cls, json_obj: dict):
        if not isinstance(json_obj, dict):
            raise cls.DeserializeErrorClass(f"Invalid data. Expecting a map in {cls.__name__}")
        extra_keys = [key for key in json_obj.keys() if key not in cls.class_properties]
        if len(extra_keys) > 0:
            raise cls.DeserializeErrorClass(
                f'Having extra properties: [{",".join(extra_keys)}] in {cls.__name__}')
        try:
            props = {}
            for prop, DeSerClass in cls.class_properties.items():
                if prop not in json_obj and prop in cls.class_property_default_values:
                    val = cls.class_property_default_values[prop]
                else:
                    val = cls.check_deser_value(prop, DeSerClass.unsafe_deserialize(json_obj[prop]))
                props[cls.class_rename_props.get(prop, prop)] = val
            instance = cls(**props)
            cls.post_deserialize(instance)
            return instance
        except KeyError as e:
            raise cls.DeserializeErrorClass(f"Missing property: {e} in {cls.__name__}")
def unsafe_deserialize ( cls , json_obj : dict ) : if not isinstance ( json_obj , dict ) : raise cls . DeserializeErrorClass ( f"Invalid data. Expecting a map in {cls.__name__}" ) extra_keys = [ key for key in json_obj . keys ( ) if key not in cls . class_properties ] if len ( extra_keys ) > 0 : raise cls . DeserializeErrorClass ( f'Having extra properties: [{",".join(extra_keys)}] in {cls.__name__}' ) try : props = { } for prop , DeSerClass in cls . class_properties . items ( ) : if prop not in json_obj and prop in cls . class_property_default_values : val = cls . class_property_default_values [ prop ] else : val = cls . check_deser_value ( prop , DeSerClass . unsafe_deserialize ( json_obj [ prop ] ) ) props [ cls . class_rename_props . get ( prop , prop ) ] = val instance = cls ( ** props ) cls . post_deserialize ( instance ) return instance except KeyError as e : raise cls . DeserializeErrorClass ( f"Missing property: {e} in {cls.__name__}" )
Deserialize the object on the data and check every possible errors in the json_obj
Deserialize the object on the data and check every possible errors in the json_obj
"""Deserialize the object on the data and check every possible errors in the json_obj""" # noinspection PyArgumentList
cls
json_obj
dict