emfjson / emfjson-jackson

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

Generic attribute types are not resolved according to actual eClass #70

Closed hallvard closed 9 years ago

hallvard commented 9 years ago

I’ve encountered an issue that I think is related to (lack of support for) generics. I have a parameterized class with a value field of the type parameter type:

abstract class SimpleClass { value : T }

class StringClass extends SimpleClass { }

emfjson seems to think value is of eType EJavaObject, even in StringClass objects. Apparently, it then defaults to a hex number format, at least the error message states "java.lang.NumberFormatException: Invalid hexadecimal”. I’ve just learned that Ecore includes a method on EClass for resolving types, so instead of structuralFeature.getEType() you should use eClass.getFeatureType(structuralFeature) where eClass is the type of the actual object, which may be a subclass of the class owning the structuralFeature.

hallvard commented 9 years ago

I have cloned and fixed according to my suggestion (both deserialise and serialise), and written a test (both saving and loading) and it seemed to work.

ghillairet commented 9 years ago

Done in https://github.com/ghillairet/emfjson/commit/32df137ff907c473f6c0047f1f9d7bc7640ee7fa

richardvobl commented 8 years ago

Sorry to comment on a long closed issue, but this fix only works with EMF 2.9 or later as eClass.getFeatureType(structuralFeature) is introduced with EMF 2.9. So please update the dependencies accordingly in the README.

ghillairet commented 8 years ago

README has been updated.