Closed jmarreroc closed 9 years ago
You can serialize the UUIDs with a JsonResource like you do with a XMIResource by overriding the method useUUIDs like this
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new JsonResourceFactory() {
@Override
public Resource createResource(URI uri) {
JsonResource resource = new JsonResource(uri) {
protected boolean useUUIDs() {
return true;
};
};
return resource;
}
});
This will generate an _id field in the JSON output with the UUID value.
Hi again ghillairet,
I tried what you said and now works perfect! I have seen that there was several changes in the project... Before all these changes i could parse a single EObject using the EObjectMapper (org.eclipselabs.emfjson.map.EObjectMapper) with this sentence EObjectMapper().to(eobject, eobject.eResource(), output_options). Is there anyway to get now the jackson ObjectNode from a single EObject?
Thank you and kind regards!
You would do it with the Jackson API
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new EMFModule(options));
JsonNode node = mapper.valueToTree(resourceOrObject);
Oh! I see! Thank you again!
Hi ghillairet,
First of all, thanks for your great work. I'm trying to persist in json format some models that i have in xmi format, so i basically put the contents of the XMI resource in your Json resource. And this is what is happening:
from my XMI fragment:
this is the generated Json fragment:
So, i can't access to the xmi:id="_e7ueQZdiEeS7gJfuiwqSVw" property in the json format... and when i try to get the EObject with the urifragment jsonResource.getEObject("_e7ueQZdiEeS7gJfuiwqSVw") i get null Object. Obviously when i try it with the xmiResource i can get the EObject correctly. I suspect that it happens because the property xmi:id is a particular functionallity of the xmi format wich EMF uses (in benefit) for locate and persist models. So, is there anyway to include the xmi:id property in my generated json? Am i missing something in the instantiation of the json Resource?
Thank you very much for your time and your work!
Kind regards.