eclipse-emfcloud / emfjson-jackson

emfjson-jackson
Other
16 stars 15 forks source link

Introduce setting for using ExtendedMetaData names #55

Closed janhicken closed 1 year ago

janhicken commented 1 year ago

The new OPTION_USE_NAMES_FROM_EXTENDED_META_DATA feature allows to configure, if property names should be extracted from ExtendedMetaData annotations.

It is enabled by default to maintain current behaviour.

When dealing with XML and Ecore models, that are generated from an XML schema definition (XSD), the following example can occcur:

<foo bar="42">
  <bar baz="hello"/>
</foo>

Here, the element <foo> has both an attribute as well as a child element called bar. A derived Ecore model would have two features, where of those has a counter appended to remove ambiguity:

interface Foo {
  /* Has @ExtendedMetadata(name="bar") */
  int getBar();

  /* Has @ExtendedMetadata(name="bar") */
  Bar getBar1();
}

The JSON mapper, however, will only serialize one of the two features listed above, because it does not resolve the ambiguity of feature names.

By disabling the newly introduced option, the internal feature names would be used instead.

This fixes https://github.com/eclipse-emfcloud/emfjson-jackson/issues/54

eneufeld commented 1 year ago

Hi @janhicken, thank you for providing the fix. Could you extend the test cases for the new case? Besides making sure the new feature works also in the future it would also be a documentation for how to use the new option. And one more question, do we need to take care of the deserialization from json to map to the correct indexed properties?

janhicken commented 1 year ago

I added some test cases, that show an exemplary usage of the new feature.

I'm afraid I don't understand what you mean exactly with the indexed property question, could you elaborate?

eneufeld commented 1 year ago

Nevermind my question, I just missed your description in the PR. The serialized json is using the internal names with the option deactivated and thus can be directly deserialzed and with the option enabled only one property is created.

Thank you for the contribution!