Closed tankwalker closed 9 months ago
Hi, thanks for submitting the issue and sorry for the delay, I could not take a look at this issue before christmas.
The problem here is that since you specified that collections are serialized as elements, the serializer does not expect the refA
collection to be rendered as attributes, it is expected to be rendered as an element. Therefore, the serializer has no idea how to handle the attribute and simply raises an UnkownAttribute
event. This carries the name and value of the attribute as well as the context element, but that does not really help since the event is raised in the middle of the parsing when the cross-references cannot be resolved, yet.
What I can do to help here is to extend the information transmitted in the UnknownAttribute
event in order to conveniently make it possible to try to treat the attribute as a misplaced element, or alternatively add a serialization setting to search in the element properties if the attribute is not attribute properties.
Best
fixed with 3477f24
Synopsis
Since the version
2.0.190
of the Ecore2Code tool, the deserialization process fails in populating corss-reference properties passing the--collectionsAreElements
properties.Description
To reproduce the problem is sufficient to generate the model code from a generic metamodel having a multivalued reference property by passing the
--collectionsAreElements
option to the Ecore2Code generation tool. The collection-valued property (i.e.,refB
in the example below) is not properly deserialized when reading the input instance model which appears to be empty at runtime, even though in the input model instance it's indeed fulfilled with data. Viceversa, by not passing the--collectionsAreElements
option to the Ecore2Code generation tool, the component correctly deserialize the multivalued property as expected.NOTE: The problem does not occur in case of a single-valued property (containment or not) as for the
refC
in theClassD
class (cfr. the example below).Example. The Ecore metamodel has a couple of classes that reference to each other.
ClassA
has a single containment reference toClassB
which, in turn, has a back reference to multiple objects of classClassA
. Further,ClassC
have a single containment and opposite reference toClassD
.Ecore model:
Instance model (original):
Instance model (read by NMF):
Additional references
A minimum working example is provided here: Mwe.zip. The command line used for the example project is:
ecore2code --collectionsAreElements -f -o src/Models -n Models -m mwe6.nmf mwe6.ecore
. The example just reads and save the instance model back to a different file, without touching anything. The Model.xmi is treated as the "original" instance model of the Ecore metamodel.