如何在 Play! 中的 YAML 文件中定义 Map!框架?
我正在使用 Play!框架,我有一个模型(一个实体),它有一个 Map 类型的变量。
为了进行一些测试,我每次启动应用程序时都会加载一个 YAML 文件,但我不知道定义 Map 的语法。
假设我有这个类,
public class aClass {
public int arg1;
public String arg2;
public Map<String, Integer> arg3;
}
我的 YAML 文件会是什么样子?我尝试过:
aClass(object1)
arg1: 34
arg2: aString
arg3: [key1: value1, key2: value2] <- What do I do here?
这是我的众多尝试之一。我不知道语法,在网上也找不到。我认为玩!使用 SnakeYAML 作为 YAML 解析器。
在文档中我找到了一些示例,但它们都不起作用。
在我的应用程序中,除了 Map 变量(示例中的 arg3)的元素大小为 0 之外,一切正常。
谢谢。
I'm using the Play! framework and I have a model (an Entity) that has a variable of type Map.
To make some tests, I load a YAML file every time I start the application, but I don't know the syntax to define a Map.
Let's say I have this class
public class aClass {
public int arg1;
public String arg2;
public Map<String, Integer> arg3;
}
What would my YAML file look like? I tried this:
aClass(object1)
arg1: 34
arg2: aString
arg3: [key1: value1, key2: value2] <- What do I do here?
This is one of my many tries. I don't know the syntax and I can't find it on the Internet. I think the Play! uses SnakeYAML as YAML parser.
In the doc I found some examples, but none of them will work.
In my application, everything works except that the Map variable (arg3 in the example) has a size of 0 element.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 Google 网上论坛 看来您需要的语法是使用问号。
该线程具有以下语法的工作映射。
所以,我想你的例子是
我已经测试过这个但是它不起作用!我建议提出一个错误来研究这个问题,因为所有文档都表明这是正确的。
According to this thread on Google Groups it appears that the syntax you need is to use a question mark.
The thread has a working map in the following syntax.
So, I guess your example would be
I have tested this however and it does not work! I would suggest raising a bug to take a look into this, because all documentation points at this being correct.