emfjson / emfjson-jackson

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

EMF model with DocumentRoot is not getting resolve #98

Open chakraborty-slx opened 7 years ago

chakraborty-slx commented 7 years ago

Using version v1.0 instead of v0.15

A common EMF model with DocumentRoot and child element inside in it, is not resolved properly.


        final ObjectMapper mapper = new ObjectMapper();
        EMFModule module = new EMFModule();
        module.configure(EMFModule.Feature.OPTION_USE_ID, true);
        module.configure(EMFModule.Feature.OPTION_SERIALIZE_TYPE, false);
        mapper.registerModule(module);

        final ResourceSetImpl jsonResourceSet = new ResourceSetImpl();
        jsonResourceSet.getPackageRegistry().put(CallgraphPackage.eNS_URI, CallgraphPackage.eINSTANCE);

        jsonResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new JsonResourceFactory(mapper));

        final Resource resource = jsonResourceSet.createResource(URI.createURI("VIRTUAL_JSON-URI"));

        DocumentRoot dr = CallgraphFactoryImpl.eINSTANCE.createDocumentRoot();
        CallGraph cg = CallgraphFactoryImpl.eINSTANCE.createCallGraph();
        Function func1 = CallgraphFactoryImpl.eINSTANCE.createFunction();
        Function func2 = CallgraphFactoryImpl.eINSTANCE.createFunction();
        Function func3 = CallgraphFactoryImpl.eINSTANCE.createFunction();

        func1.setName("func1");
        func2.setName("func2");
        Call call1 = CallgraphFactoryImpl.eINSTANCE.createCall();
        call1.setCallee(func1);
        call1.setCaller(func2);
        cg.getCall().add(call1);
        cg.getFunction().add(func1);
        cg.getFunction().add(func2);
        cg.getFunction().add(func3);
        dr.setCallGraph(cg);

        ((JsonResource) resource).setID(cg, "1");
        resource.getContents().add(dr);

        try {

            JsonNode result = mapper.valueToTree(resource);

            String jsonString = mapper.writeValueAsString(resource);
            System.out.println(jsonString);
        } catch (JsonProcessingException e1) {
            e1.printStackTrace();
        }

Output is only

{"@id":"_Pg7e0EVYEeeDcbTRWgbgUA"}
kvcheban commented 3 years ago

Same issue using version 1.2.0 instead of 0.13.0. Could someone provide a fix? Or maybe help with finding a fix?