emfjson / emfjson-jackson

JSON Binding for Eclipse Modeling Framework
https://emfjson.github.io
Other
80 stars 23 forks source link

Support for dynamic properties #25

Closed ghillairet closed 11 years ago

ghillairet commented 11 years ago

This feature would provide support for loading/serializing Object specific properties with no direct mapping in corresponding EClass. For example if we have the following EClass:

class User {
  attr String[1] name;
} 

and following JSON Object:

{
    name: 'Randy',
    'specific-property': 'some-value'
}

The property name is mapped to the EAttribute name but the second property does have any equivalent and is specific to this object.

A way to keep this information is to defined a Map.Entry in the EClass as this:

class User {
  attr String[1] name;
  @JSON(dynamicMap="true")
  val ecore.EStringToStringMapEntry[*] entries;
}

This one is annotated with the @JSON annotation and have for key dynamicMap sets to true, it's name is arbitrary. This MapEntry will be use to store the Object dynamic properties, that could be access like this:

eObject.getEntries().get('specific-property') -> 'some-value'