|
It's probably the same with ArrayCollections or Arrays of enums.
The only way to fix this is to rewrite the collection content after readExternal. In the trunk, this can be done by using Tide.getContext().meta_mergeExternalData(collection/map). The best solution would be to plug specific IDataInput implementation that overrides the readObject method and (when necessary) transforms the result before returning it. I don't know how to achieve that and if it is even possible...
This issue also causes the mergeMap function in the tide EntityManager to fail when the key is a enum.
Line 985 in tide EntityManager (2.1.0.RC2) where the keys are compared: if (_mergeUpdate) { for each (key in prevMap.keySet) { var found:Boolean = false; for each (var k:Object in map.keySet) { if (objectEquals(k, key)) { found = true; break; } } if (!found) prevMap.remove(key); } } Perhaps this could be fixed by changing objectEquals to include something like this: if (obj1 is Enum && obj2 is Enum && obj1 != null && obj1.equals(obj2)) return true; Should a new Jira issue be created for this? This issue
Your suggestion looks fine, but do you have any example or test of a non working merge of map with enum keys using the latest trunk ? Forget it, you're right, my unit test was bad.
The fix should solve the issue for GDS collections (BasicMap, UIDSet, UIDList, Persistent*). There is no possible solutions for simple ArrayCollections that contain Enum instances (except by check their content by hand).
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
public function readExternal(input:IDataInput):void {
var elements:Array = input.readObject() as Array; // <- New Enum instances are created here... constants aren't used
for each (var pair:Array in elements) {
_keySet.addItem(pair[0]);
_values.addItem(pair[1]);
_entrySet[pair[0]] = pair;
}
}