emfjson-jackson icon indicating copy to clipboard operation
emfjson-jackson copied to clipboard

EMF model with DocumentRoot is not getting resolve

Open chakraborty-slx opened this issue 8 years ago • 1 comments

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"}

chakraborty-slx avatar May 30 '17 16:05 chakraborty-slx

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

kvcheban avatar Mar 04 '21 17:03 kvcheban