简体   繁体   English

从黄瓜功能文件更新 json 有效负载的最佳方法

[英]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.

相关问题 如何在Cucumber中将原始数据json格式从特征文件传递到stepdefinition文件 - How to pass raw data json format from feature file to stepdefinition file in Cucumber 如何从Jenkins读取Cucumber功能文件 - How to read Cucumber feature file from Jenkins Cucumber 功能文件未从 Maven 执行 - Cucumber feature file not executing from Maven 有没有办法将数据从 Java 步骤定义类发送到 Cucumber 框架中的特征文件? - Is there any way to send data from Java step definition class to feature file in Cucumber framework? 格式化黄瓜功能文件 - Formatting Cucumber Feature file 测试框架-用JSON代替Gherkin功能文件的黄瓜 - Test Framework - Cucumber with JSON instead of Gherkin Feature file 如何在运行时使用带有 io.cucumber 的最新黄瓜版本从特征文件中读取黄瓜特征名称 - How to read cucumber feature name from feature file during runtime using latest cucumber version with io.cucumber 在 Spring 中消耗大量 json 有效负载的最佳方法是什么? - Best way to approach consuming large json payload in Spring? 如何使用正则表达式从黄瓜功能文件中提取特定场景 - How to pull a specific scenario from a cucumber feature file using regex cucumber:如何从特定功能文件运行标记场景 - cucumber: how to run a tagged scenario from a specific feature file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM