eclipse-emfcloud / emfjson-jackson

emfjson-jackson
Other
16 stars 15 forks source link

Resolve static generic type bindings in deserialization #41

Closed janhicken closed 2 years ago

janhicken commented 2 years ago

Suppose you have the following Xcore model:

@Ecore(nsURI="http://my-model/1.0")
package produce

class Container<T> {
  String name
  contains T content
}

interface Bananas {
  long count
}

class BananaContainer extends Container<Bananas> {}

When the following JSON string is deserialized, ...

{
  "eClass": "http://my-model/1.0#//BananaContainer",
  "name": "foo",
  "content": {
    "count": 1337
  }
}

... we know, that content must be of type Bananas. In this case, the generic type T can be resolved statically in case of deserializing a BananaContainer instance.

The current implementation fails to resolve the type T correctly and deserializes content as an empty EObject. As a workaround, a type info ("eClass": "...") can be added to the content object, like this:

{
  "eClass": "http://my-model/1.0#//BananaContainer",
  "name": "foo",
  "content": {
    "eClass": "http://my-model/1.0#//Bananas",
    "count": 1337
  }
}

I'd like to omit the redundant type info for cases where the generic type can be resolved.

This can probably be done using EcoreUtil.getReifiedType.