eclipse-sirius / sirius-emf-json

JSON-based EMF Resource implementation - part of Eclipse Sirius
https://eclipse.dev/sirius/sirius-web.html
Eclipse Public License 2.0
5 stars 10 forks source link

Be more relaxed/lenient in handling attributes cardinality on load #3

Closed pcdavid closed 2 years ago

pcdavid commented 2 years ago

The idea is to support the use case mentioned at https://github.com/eclipse-sirius/sirius-components/issues/615, i.e. loading a JSON resource when the metamodel has been modified in a specific way: an attribute which was single-valued at the time the model was serialized is now many-valued when reloading the resource (or vice versa).

The changes are relatively trivial: instead of blindly trusting the cardinality in the current (at load time) version of the metamodel, also check the kind of JSON value we have. If it matches, do as before. Otherwise:

I have tested this with EAttributes, and it seems to work, at least on simple cases.

The same approach could probably be used for references too, i.e. when doing String id = value.getAsString(); blindly in deserializeSingleNonContainmentEReference() and JsonArray array = value.getAsJsonArray(); in deserializeMultipleNonContainmentEReference() for example.

Before proceeding I'd like @sbegaudeau and @gcoutable's opinion on the general approach, and if this behavior should be controlled by a load option (probably) or not.

sbegaudeau commented 2 years ago

I have not reviewed the code yet but I agree on the change in behavior.