我有一个例子,其中我有json指针和swagger json文件。我需要得到need指针所指向的行号。
有办法这样做吗,我使用了ObjectMapper,我得到了jsonNode,我在代码中也看到了,当json文件被解析时,JsonParser有关于行号的信息,我有一种方法来获得每个ObjectNode的行号,或者传递jsonPointer并得到行号。
以下是代码:
public class JsonPointerUtil {
static ObjectMapper om = new ObjectMapper();
private JsonNode jsonNode;
public JsonPointerUtil(File json) throws IOException {
jsonNode = com.xyz.util.JsonPointerUtil.om.readTree(json);
}
public String getJsonBlockForPointer(String jsonPtr) {
if (StringUtils.isEmpty(jsonPtr))
return null;
JsonNode at = jsonNode.at(jsonPtr);
return at.toString();
}}
所以在getJsonBlockForPointer方法中,我用指针得到json节点,json节点是指针指向的准确的json块,我也需要指向json块的行号,有什么方法可以得到吗?
我的要求是,行号由UI端代码使用,有多个UI应用程序调用相同的后端服务,在UI端,jsonPointer库向我提供所有信息(行、行、jsonPointer),但是由于有多个UI应用程序在使用相同的服务,所以我想从后端发送所有信息。
发布于 2022-10-01 00:51:03
发布了很长一段时间后,我们最终只使用了javascript,我们从java调用了javascript,并传递了相关细节。
我们基本上用了
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
Invocable inv = (Invocable) engine;
long start = new Date().getTime();
Gson gson=new Gson();
parse = inv.invokeFunction("getLineNumbers", jsonPointers, swaggerAsString);从java调用javascript文件。
https://stackoverflow.com/questions/56887091
复制相似问题