emfjson / emfjson-jackson

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

Possibility to always add the type to EObjects. #110

Open AlbinTheander opened 4 years ago

AlbinTheander commented 4 years ago

Currently I have a use-case where I need to deserialize an array of different types of EObjects into a standard java list. To be able to deal with the generics part of it, I need the type to be serialized in all the objects. (So the deserializer can create the correct EObject subtype.)

Currently there is a function in EObjectTypeProperty.java:

private boolean shouldSaveType(EClass objectType, EClass featureType, EStructuralFeature feature) {
    return objectType != featureType && objectType != EcorePackage.Literals.EOBJECT;
}

I don't know if there is a reason for not including it when the object type is the same as the feature type. I can see how it shouldn't be needed for most cases, but I can't see that it would be a problem to always include it.

I would like to either remove that condition, or add a feature flag to always include the type.

I am fully prepared to try to put together a pull request, but I would like some input on which way to go; removing it or adding a feature flat. (Or possibly tell me that it's already possible and I misunderstood things.)