[英]Best way to update json payload from cucumber feature file
I have a complex Json which acts like a input to a webservice.我有一个复杂的 Json,它的作用类似于 Web 服务的输入。 I have created necessary POJO classes for it and I am using Jackson object mapper in my code.
我已经为它创建了必要的 POJO 类,并且在我的代码中使用了 Jackson 对象映射器。
What could be the best way to update the partial Json data from cucumber data tables?从黄瓜数据表中更新部分 Json 数据的最佳方法是什么?
Thanks in advance !!!提前致谢 !!!
Original Json:原始Json:
{
"accNum": "Dummy_Account",
"customerData": {
"customerName": "Dummy_Name",
"customerAddress": "Dummy_Address"
},
"accountData": {
"cashAccountRef": "Dummy",
"acntCrncy": "EUR",
"foreignCurrencyAccounts": [
{
"foreignCurrency": "USD",
"foreignCrncyAcntRef": "Dummy2"
}
]
}
]
}
Cucumber Feature File黄瓜功能文件
Given Prepare Input request for below data
| accNum | 12345 |
| customerData.customerName | New Name|
| accountData.foreignCurrencyAccounts[0].foreignCurrency | EUR |
Final Json to be passed as input要作为输入传递的最终 Json
{
"accNum": "12345",
"customerData": {
"customerName": "New Name",
"customerAddress": "Dummy_Address"
},
"accountData": {
"cashAccountRef": "Dummy",
"acntCrncy": "EUR",
"foreignCurrencyAccounts": [
{
"foreignCurrency": "EUR",
"foreignCrncyAcntRef": "Dummy2"
}
]
}
]
}
If you're using POJO then stick to this approach.如果您使用的是 POJO,请坚持使用这种方法。 Using setter to update value of the key, of course you can use builder style for setter to make it more easier to read.
使用 setter 来更新 key 的值,当然你也可以使用 builder 风格的 setter 让它更容易阅读。
I found only this way我发现只有这样
((ObjectNode) parent).putRawValue(valueOfKeyToModify, new RawValue(newValue));
The problem arises when there are many identical keys.当有许多相同的键时,就会出现问题。 And then you need to read the tree and go around it until it matches exactly the key that needs to be changed.
然后您需要阅读树并绕过它,直到它与需要更改的键完全匹配。
And if you need to lay string, then you must also specify quotes, since it lays the raw value如果你需要放置字符串,那么你还必须指定引号,因为它放置了原始值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.