是否可以使用Yamlslurper和YamlBuilder查找重复的属性名称?
如果我有这样的yaml文件:
obj:
- name: 'msg'
patterns:
'("ssn":")([^"]*)(")' : '$1xxxxxxxxx$3'
'("cvv":")([^"]*)(")' : '$1xxxx$3'
'("ssn":")([^"]*)(")' : '$1xxxxxxxxx$3'
如果我使用groovy yamlslurper类来加载它,则“模式”对象将具有两个属性,其中包括以下名称:(
- “ ssn”:“:”)([^'^“)*)([^'']*)( ”)
- (“ cvv”:“)([^“^”]*)(“)
输入中的第三个属性具有与第一个属性名称相同的名称,因此第三个属性将覆盖第一个(或VICE反之亦然)。
有什么方法可以使用Yamlslurper或Yamlbuilder的某种组合来以某种方式检测到输入是否具有重复的属性名称?
我可以看到更改该文件的预期语法,以期期望这样的格式:
obj:
- name: 'msg'
patterns:
- '("ssn":")([^"]*)(")' : '$1xxxxxxxxx$3'
- '("cvv":")([^"]*)(")' : '$1xxxx$3'
- '("ssn":")([^"]*)(")' : '$1xxxxxxxxx$3'
将使我能够检测重复。如果我无法使用原始格式在输入上检测重复的属性名称,则将考虑更改规格以需要修改格式。
If I have a yaml file like this:
obj:
- name: 'msg'
patterns:
'("ssn":")([^"]*)(")' : '$1xxxxxxxxx$3'
'("cvv":")([^"]*)(")' : '$1xxxx$3'
'("ssn":")([^"]*)(")' : '$1xxxxxxxxx$3'
If I use the Groovy YamlSlurper class to load this, the "patterns" object will have two properties, with the following names:
- ("ssn":")([^"]*)(")
- ("cvv":")([^"]*)(")
The third property in the input has a name identical to the first property name, so the third one will override the first (or vice versa).
Is there any way I could use some combination of YamlSlurper and perhaps YamlBuilder to somehow detect that the input has a duplicate property name?
I can see that changing the expected syntax of this file so that it expects a format like this:
obj:
- name: 'msg'
patterns:
- '("ssn":")([^"]*)(")' : '$1xxxxxxxxx$3'
- '("cvv":")([^"]*)(")' : '$1xxxx$3'
- '("ssn":")([^"]*)(")' : '$1xxxxxxxxx$3'
Would give me the ability to detect duplicates. If I can't detect duplicate property names on the input using the original format, I will consider changing the spec to require the modified format.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Groovy.yaml.yamlslurper
有一个Jackson
库。yamlslurper.parse()
- > yamlconverter.convertyamltojson() - >
Jackson
因此,您可以使用它来检测首先重复:
此代码引发异常:
behind
groovy.yaml.YamlSlurper
there is ajackson
library.YamlSlurper.parse()
-> YamlConverter.convertYamlToJson() ->
jackson
so, you could use it to detect first duplicate:
this code throws exception: