我刚发现存在JSON
的变体JSON-LD
。
您知道是否可以将JSON-LD
转换为Java Object
而无需Java类,jsonld-java或Apache Jena吗?
或者,我可以从JSON-LD
创建一个Java类,在运行时加载它,并使用它将JSON-LD
转换为该类的实例吗?
我阅读了两个实现的文档,但对此一无所获。也许我读得不好?
答案 0 :(得分:1)
进行Google搜索后,我进入了一个库,该库会将JSON-LD解码为“未定义” Object
。
// Open a valid json(-ld) input file
InputStream inputStream = new FileInputStream("input.json");
// Read the file into an Object (The type of this object will be a List, Map, String, Boolean,
// Number or null depending on the root object in the file).
Object jsonObject = JsonUtils.fromInputStream(inputStream);
// Create a context JSON map containing prefixes and definitions
Map context = new HashMap();
// Customise context...
// Create an instance of JsonLdOptions with the standard JSON-LD options
JsonLdOptions options = new JsonLdOptions();
// Customise options...
// Call whichever JSONLD function you want! (e.g. compact)
Object compact = JsonLdProcessor.compact(jsonObject, context, options);
// Print out the result (or don't, it's your call!)
System.out.println(JsonUtils.toPrettyString(compact));
https://github.com/jsonld-java/jsonld-java
显然,它也可以从字符串中获取,就像从文件或其他来源读取它一样。我无法告诉您如何访问object
的内容。不过,该文档似乎还算不错。
这似乎是一个活跃的项目,因为上一次提交仅在4天前,有30位贡献者。许可证对您有任何影响的BSD 3-Clause。
我与该项目无关。我不是作者,也没有提出任何拉取请求。就是我发现的东西。
祝你好运,希望对你有帮助!
答案 1 :(得分:0)
请参阅此页面:JSON-LD Module for Jackson