adapter: add xml deserialization
This MR merges feature/xml_deserilization
into master
. It comes with deserialization tests and serialize + deserialize tests, just like the json module.
There's just one thing left to discuss, the problem I also mentioned in yesterday's meeting:
I'm using a TypedDict
to pass the modeling kind of submodels and submodel elements to the respective constructor only when it's specified in the xml document, see _get_modeling_kind_kwarg().
I'm doing it this way because in my opinion defining the default modeling kind should be a task of the respective model constructors, not of the deserialization, since the default value is also only defined in the model part of Details of the Asset Administration Shell Part 1
(see chapter 4.7.2.3), not in the serialization/deserialization part.
The problem is, that I'm importing TypedDict
from mypy_extensions
, because it's only available from typing
in python 3.8+. mypy
is not a runtime dependency, thus I can't use mypy_extensions
in code that is not for testing only.
An alternative would be to also just define the default modeling kind in the xml_deserialization
, just like the json_deserialization
does.
I'd like to hear your opinion on this, maybe you can come up with other alternatives.
The rest of this merge request is ready for code review btw.
Merge request reports
Activity
I'm using a
TypedDict
to pass the modeling kind of submodels and submodel elements to the respective constructor only when it's specified in the xml document, see _get_modeling_kind_kwarg(). I'm doing it this way because in my opinion defining the default modeling kind should be a task of the respective model constructors, not of the deserialization, since the default value is also only defined in the model part ofDetails of the Asset Administration Shell Part 1
(see chapter 4.7.2.3), not in the serialization/deserialization part.As I already said in the meeting, I consider this to be a flaw of the XML format specification: It should specify somehow, how a non-present modeling kind in an XML document is to be interpreted. As the constructor's default value is just a convenience functionality for users of our Python framework, it should not have an impact on the semantics of the XML format. Thus, I strongly vote for hardcoding the default value in the XML deserialization.
- Resolved by Michael Thies
You should remove the "TODO" docstring of
_construct_concept_description()
. Apart from that: Approved!Is there anything left to do? Why is the MR tagged as "WIP"?
added 1 commit
- 2b875550 - adapter: explicitly define INSTANCE as ModelingKind default value
I explicitly defined the default value for modeling kind in the XML deserialization. I also removed the TODO docstring as requested.
Edited by Leon Mauritz Mölleradded 1 commit
- e271d811 - test.xml: don't access protected property _kind
mentioned in commit c1e2a8a6