用外部变量解析yaml文件

发布于 2025-02-12 20:47:18 字数 539 浏览 0 评论 0原文

我正在尝试使用杰克逊(Jackson)从一个巨大的yaml文件中获取一些值,并将其读成树以获取所需的路径。

ObjectMapper om = new ObjectMapper(new YAMLFactory())
om.readTree(file).path("connections").path("connection")

它无法在以下行中解析文件:

config.file.path: {{DIR}}/config/

com.fasterxml.jackson.core.jsonparseexception:期望一个字段名称 (YAML中的标量值),而是这样做: < org.yaml.snakeyaml.events.mappingstartevent(Anchor = null,tag = null, 隐式= true)>在[源:(StringReader);线:80,列:18]

由于我不需要这条线,是否有办法告诉解析器跳过/忽略它?

I am trying to get some values out of a huge YAML file using Jackson and read as a tree to get the path I need.

ObjectMapper om = new ObjectMapper(new YAMLFactory())
om.readTree(file).path("connections").path("connection")

It fails to parse the file on the following line:

config.file.path: {{DIR}}/config/

com.fasterxml.jackson.core.JsonParseException: Expected a field name
(Scalar value in YAML), got this instead:
<org.yaml.snakeyaml.events.MappingStartEvent(anchor=null, tag=null,
implicit=true)> at [Source: (StringReader); line: 80, column: 18]

As I don't need this line, is there a way to tell the parser to skip/ignore it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文