如何从Java对象创建以下YAML内容?我使用Jackson Yaml,我想创建一个这样的YAML文件。
scrape_configs:
- job_name: sampleName //how to create this line, what does it mean? it is no sequence right?
scrape_timeout: 10s
scrape_interval: 10s
metrics_path: samplePath
file_sd_configs: //works with List in List from the Java Object
- files:
- sampleFile
答案 0 :(得分:1)
- attribute: value
attribute2: value
相当于
-
attribute:value
attribute2: value
所以它是一个包含对象的List。
如有疑问,请使用在线转换器将其转换为JSON。 JSON结果是:
{
"scrape_configs": [
{
"job_name": "sampleName",
"scrape_timeout": "10s",
"scrape_interval": "10s",
"metrics_path": "samplePath",
"file_sd_configs": [
{
"files": [
"sampleFile"
]
}
]
}
]
}
注意: 转换工具的示例:https://www.json2yaml.com/