0
我使用EMFJson来序列化EMF Ecore模型。我能够从现有的模型创建一个JSON字符串。然而,回来的路不适合我。我想下面的两个片段:使用EMFJson读取JSON字符串
第一次尝试:
ObjectMapper objectMapper = EMFModule.setupDefaultMapper();
objectMapper.reader().forType(MyClass.class).readValue(string);
第二次尝试:
ObjectMapper objectMapper = EMFModule.setupDefaultMapper();
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry()
.getExtensionToFactoryMap()
.put("json", new JsonResourceFactory());
try {
Resource resource = objectMapper
.reader()
.withAttribute(EMFContext.Attributes.RESOURCE_SET, resourceSet)
.withAttribute(EMFContext.Attributes.RESOURCE_URI, null)
.forType(Resource.class)
.readValue(string);
} catch (IOException e1) {
e1.printStackTrace();
}
对于这两种尝试,我收到以下异常:了java.lang.RuntimeException:无法创建uri默认的资源
我想第二种方法根本无法工作,因为我不知道该怎么提供作为RESOURCE_URI。示例here我以两次读取文件而不是字符串为基础。有人有一个想法如何使这项工作?谢谢!