Skip to content
This repository was archived by the owner on Jun 26, 2021. It is now read-only.
This repository was archived by the owner on Jun 26, 2021. It is now read-only.

EMF model with DocumentRoot is not getting resolve #98

@chakraborty-slx

Description

@chakraborty-slx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions