Commit 6278d03f authored by Michael Thies's avatar Michael Thies
Browse files

Merge branch 'fix/move_inverse_dicts' into 'master'

Improve/fix JSON deserialization

See merge request acplt/pyaas!19
parents 354105c6 e1ec36c2
Pipeline #264528 passed with stage
in 3 minutes and 9 seconds
"""
Dicts to serialize enum classes
Dicts to serialize and deserialize enum classes
"""
from typing import Dict
......@@ -76,3 +76,15 @@ IEC61360_LEVEL_TYPES: Dict[model.concept.IEC61360LevelType, str] = {
model.concept.IEC61360LevelType.NOM: 'Nom',
model.concept.IEC61360LevelType.TYP: 'Typ',
}
MODELING_KIND_INVERSE: Dict[str, model.ModelingKind] = {v: k for k, v in MODELING_KIND.items()}
ASSET_KIND_INVERSE: Dict[str, model.AssetKind] = {v: k for k, v in ASSET_KIND.items()}
KEY_ELEMENTS_INVERSE: Dict[str, model.KeyElements] = {v: k for k, v in KEY_ELEMENTS.items()}
KEY_TYPES_INVERSE: Dict[str, model.KeyType] = {v: k for k, v in KEY_TYPES.items()}
IDENTIFIER_TYPES_INVERSE: Dict[str, model.IdentifierType] = {v: k for k, v in IDENTIFIER_TYPES.items()}
ENTITY_TYPES_INVERSE: Dict[str, model.EntityType] = {v: k for k, v in ENTITY_TYPES.items()}
IEC61360_DATA_TYPES_INVERSE: Dict[str, model.concept.IEC61360DataType] = {v: k for k, v in IEC61360_DATA_TYPES.items()}
IEC61360_LEVEL_TYPES_INVERSE: Dict[str, model.concept.IEC61360LevelType] = \
{v: k for k, v in IEC61360_LEVEL_TYPES.items()}
KEY_ELEMENTS_CLASSES_INVERSE: Dict[model.KeyElements, type] = {v: k for k, v in model.KEY_ELEMENTS_CLASSES.items()}
......@@ -29,22 +29,12 @@ import pprint
from typing import Dict, Callable, TypeVar, Type, List, IO, Optional
from ... import model
from .._generic import MODELING_KIND, ASSET_KIND, KEY_ELEMENTS, KEY_TYPES, IDENTIFIER_TYPES, ENTITY_TYPES,\
IEC61360_DATA_TYPES, IEC61360_LEVEL_TYPES
from .._generic import MODELING_KIND_INVERSE, ASSET_KIND_INVERSE, KEY_ELEMENTS_INVERSE, KEY_TYPES_INVERSE,\
IDENTIFIER_TYPES_INVERSE, ENTITY_TYPES_INVERSE, IEC61360_DATA_TYPES_INVERSE, IEC61360_LEVEL_TYPES_INVERSE,\
KEY_ELEMENTS_CLASSES_INVERSE
logger = logging.getLogger(__name__)
MODELING_KIND_INVERSE: Dict[str, model.ModelingKind] = {v: k for k, v in MODELING_KIND.items()}
ASSET_KIND_INVERSE: Dict[str, model.AssetKind] = {v: k for k, v in ASSET_KIND.items()}
KEY_ELEMENTS_INVERSE: Dict[str, model.KeyElements] = {v: k for k, v in KEY_ELEMENTS.items()}
KEY_TYPES_INVERSE: Dict[str, model.KeyType] = {v: k for k, v in KEY_TYPES.items()}
IDENTIFIER_TYPES_INVERSE: Dict[str, model.IdentifierType] = {v: k for k, v in IDENTIFIER_TYPES.items()}
ENTITY_TYPES_INVERSE: Dict[str, model.EntityType] = {v: k for k, v in ENTITY_TYPES.items()}
KEY_ELEMENTS_CLASSES_INVERSE: Dict[model.KeyElements, type] = {v: k for k, v in model.KEY_ELEMENTS_CLASSES.items()}
IEC61360_DATA_TYPES_INVERSE: Dict[str, model.concept.IEC61360DataType] = {v: k for k, v in IEC61360_DATA_TYPES.items()}
IEC61360_LEVEL_TYPES_INVERSE: Dict[str, model.concept.IEC61360LevelType] = \
{v: k for k, v in IEC61360_LEVEL_TYPES.items()}
# #############################################################################
# Helper functions (for simplifying implementation of constructor functions)
......@@ -268,7 +258,7 @@ class AASFromJsonDecoder(json.JSONDecoder):
@classmethod
def _construct_reference(cls, dct: Dict[str, object], object_class=model.Reference) -> model.Reference:
keys = [cls._construct_key(key_data) for key_data in _get_ts(dct, "keys", list)]
return model.Reference(tuple(keys))
return object_class(tuple(keys))
@classmethod
def _construct_aas_reference(cls, dct: Dict[str, object], type_: Type[T], object_class=model.AASReference)\
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment