【问题标题】:How to construct empty Array list in Json using Rest Assured如何使用 Rest Assured 在 Json 中构造空数组列表
【发布时间】:2022-01-08 21:50:14
【问题描述】:

我正在序列化 POJO 类的 Json。我想在 Request 中发送空数组,但是当我将 null 或空值传递给 pojo 类中的属性时,我在数组列表中得到 [""] 而不是 []

Expected:  "Key": []

But I am getting: "Key":[""]

我的宝:

public class Sample {

    private List<String> Key=null;
}

测试数据生成器类:

Sample s = new Sample();
s.Key = ""; // Even if i give null here, i am getting null at the json payload.

请建议以下方法为 Key 构造一个空数组。

{
"Key": []
}

【问题讨论】:

    标签: json api selenium automation rest-assured


    【解决方案1】:

    只需初始化新的ArrayList,像这样。

    Sample s = new Sample();
    s.Key = new ArrayList<>();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 1970-01-01
      • 2017-10-06
      • 1970-01-01
      相关资源
      最近更新 更多