emfjson / emfjson-jackson

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

EEnum Serialization #38

Closed LeonLiuY closed 10 years ago

LeonLiuY commented 10 years ago

I've tried this great tool but I found an error about EEnum Serialization. EEnum attribute will not be serialized if it has the default value 0.

And I found the reason:

In EAttributeSerializer.java there is:

static boolean isCandidate(EObject eObject, EAttribute eAttribute) {
    return eObject.eIsSet(eAttribute) && !eAttribute.isDerived() && 
            !eAttribute.isTransient() && !eAttribute.isUnsettable();
}

If an EEnum object has the default value 0, eObject.eIsSet will return false. (if the object has a non-default value, it becomes true).

You can test it by User.sex in the test model.

I fixed it with

static boolean isCandidate(EObject eObject, EAttribute eAttribute) {
    return (eObject.eIsSet(eAttribute) || eAttribute.getEType() instanceof EEnum) && !eAttribute.isDerived() && 
            !eAttribute.isTransient() && !eAttribute.isUnsettable();
}

but it is related with some test cases and I'm not sure whether this fix is the best way. I report this to you and I appreciate your updates on this.

ghillairet commented 10 years ago

It is fixed now, added in debaab61e74196e324a68678209111dba3692431