eclipse-emfcloud / emfjson-jackson

emfjson-jackson
Other
16 stars 15 forks source link

Type Information is not serialized #64

Closed nestabentum closed 4 months ago

nestabentum commented 5 months ago

I'm trying to build an EMF modeling tool by customizing the Coffee Editor. Currently, my goal is to implement the Tree Editor as meta-model agnostic as possible. To achieve this, I realized that type information must be serialized by the model server. Unfortunately, there seems to be a bug that prevents the type information from being serialized.

I modified the CoffeTreeJsonCodec in the Coffee Editor by adding emfModule.configure(EMFModule.Feature.OPTION_SERIALIZE_TYPE, true); - unfortunately this does not have an effect. (The comment in this class already suggests so: // FIXME investigate why eClass (type) is not serialized for nested elements // e.g. processor child of control unit). With debugging, I was able I was able to identify the method EObjectTypeProperty#serialize as problematic. It only writes the type information when the corresponding EObject is the root or objectType != featureType && objectType != EcorePackage.Literals.EOBJECT.

As a user of the EMFModule I would expect type information to be serialized when using the corresponding action, regardless of further constraints. Are there any plans to fix this? Are there known workarounds?

martin-fleck-at commented 5 months ago

@nestabentum Thank you for your interest in this project. I'll try to have a look at this soon as I'm also not fully sure why those restrictions are in place. In theory, with the EcoreTypeInfo we should be able to properly determine the type in any case. I'll let you know as soon as I find out more.

nestabentum commented 5 months ago

Hi, are there any updates on this issue?

martin-fleck-at commented 5 months ago

@nestabentum Thank you for following up! I didn't have as much time as I'd hoped to go deeper, unfortunately. From a first glance, we should be able to fix this and I don't know why the restriction was implemented in the first place. I'll do a deep dive on Monday and come back to you then.

martin-fleck-at commented 5 months ago

@nestabentum I had a deeper look at the issue and it seems that the condition was added to minimize "unnecessary" type information (see https://github.com/emfjson/emfjson-jackson/issues/93 and the two related commits). I assume the rationale behind it is that if you know the type of the root node you can derive the types of the other nodes based on the metamodel, so you could skip that during serialization. However, in cases such as yours, we still want to have that information.

To not break backwards compatibility, I'd suggest to add a dedicated option to turn off the minimization, see https://github.com/eclipse-emfcloud/emfjson-jackson/pull/65. Could you please check whether you think that will solve the issue for you as well?

nestabentum commented 4 months ago

Looks good to me!

martin-fleck-at commented 4 months ago

Nightly available at https://download.eclipse.org/emfcloud/emfjson-jackson/p2/nightly/2.3/2.3.0.202404220745/