emfjson / emfjson-jackson

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

manage root proxy containment #76

Closed Dufgui closed 8 years ago

Dufgui commented 8 years ago

Hello,

due to performance and functionnal reason (cypher and splitting managment), we split by ourself Resources. It's work with Xml but not with your json lib. So i add this use case managment. Hope this code is enought good to be interated.

Have a nice day

ghillairet commented 8 years ago

Thanks, I'll look at it, that's something I wanted to add.

Dufgui commented 8 years ago

you 're welcome. ;o) I you have the time just to release a compatibility version of emfjson-mongo. Because i build a snap localy but it's not really good and the previous version is ko with the 0.13 version

ghillairet commented 8 years ago

This should be included in version 0.15.

For your other question, emfjson-mongo will be reworked completely, the correct implementation is more a proof of concept. Keep a look on https://github.com/emfjson/emfjson-mongo

Dufgui commented 8 years ago

Hello, i add the type when serialize external proxy. Sorry for the merge. My git do a strange bug when i rebase. but you can review. and if it's ok I can rework my commit.

Dufgui commented 8 years ago

So i test your advice and all is working fine ;o). Thanks. So i commit it. Say me if there is still something to touch

ghillairet commented 8 years ago

Have you tested the master branch? see comment https://github.com/emfjson/emfjson-jackson/issues/78

ghillairet commented 8 years ago

Closing for now, please tell me if you have still those issues with 0.15.

Dufgui commented 8 years ago

Hello, i take the 0.15 and create a unit test with containment proxy of an abstract class. And it's failed ! the i switch back to my branch and it's work. Is it help you ? You want other unit test ? or is it enought ?

https://github.com/Dufgui/emfjson-jackson/commit/1902d210355a3474bb99b49b6ce85f250581cd19

Dufgui commented 8 years ago

Do you want i rebase my branch to the 0.15, in order to simplify the merge?

Dufgui commented 8 years ago

I made a pursh to rename my test file to avoid conflict on merge with 0.15

ghillairet commented 8 years ago

Thanks. If the unit test you added shows the problem it's enough for me to see what's wrong with current version.

Dufgui commented 8 years ago

So I try a newbranch updated with your 0.15 tag. Hope my tests is more clear

ghillairet commented 8 years ago

Your test doesn't look to pass either for XMI resources.

If I have test2.xmi that contains

<?xml version="1.0" encoding="ASCII"?>
<model:PhysicalNode xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:model="http://www.emfjson.org/jackson/model" label="p2"/>

and test1.xmi that contains

<?xml version="1.0" encoding="ASCII"?>
<model:PhysicalNode xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:model="http://www.emfjson.org/jackson/model" label="p1">
  <child xsi:type="model:PhysicalNode" href="src/test/resources/xmi/test2.xmi#/"/>
</model:PhysicalNode>

And then I run the following test, it will fail on assertNotSame(p2.eResource(), p1.eResource());

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(ModelPackage.eNS_URI, ModelPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry()
    .getExtensionToFactoryMap()
    .put("xmi", new XMIResourceFactoryImpl());

Resource x1 = resourceSet.getResource(URI.createURI("src/test/resources/xmi/test1.xmi"), true);
PhysicalNode p1 = (PhysicalNode) x1.getContents().get(0);

AbstractNode p2 = p1.getChild().get(0);
assertTrue(p2.eIsProxy());
assertNotSame(p2.eResource(), p1.eResource());

But this one will succeed, if you resolve the proxy.

AbstractNode p2 = p1.getChild().get(0);
assertTrue(p2.eIsProxy());
assertSame(p2.eResource(), p1.eResource());

EObject resolve = EcoreUtil.resolve(p2, resourceSet);
assertNotSame(resolve.eResource(), p1.eResource());
ghillairet commented 8 years ago

If you want the first test to succeed, or you don't want to resolve manually, you should set the reference property resolveProxies to true.

In xcore it is done with resolving keyword.

abstract class AbstractNode {
    String label
    contains resolving AbstractNode[] child opposite parent
}

During deserialization, proxies will be put in child list, only when you access an element in that list, it will be resolve.

Dufgui commented 8 years ago

I have no more time to work on this for the moment maybe later.... in 1 month i think. sorry