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我以兩次讀取文件而不是字符串爲基礎。有人有一個想法如何使這項工作?謝謝!