Skip to content

修改数组中的数据NON_EXTENSIBLE模式有的时候无法检测出来 #200

Description

@LCG0214
 String expectedJson = "{\"name\":\"lcgui\",\"age\":18,\"hobby\":[\"basketball\",\"football\"],\"address\":{\"city\":\"beijing\",\"street\":\"chaoyang\"}}";
    // 这里修改了年龄:18 -> 20,地址:beijing -> nanjing,hobby:basketball -> pingpong
    String actualJson = "{\"name\":\"lcgui\",\"age\":20,\"hobby\":[\"pingpong\",\"football\"],\"address\":{\"city\":\"nanjing\",\"street\":\"chaoyang\"}}";
    // 使用 JSONCompare 进行比较
    JSONCompareResult result = JSONCompare.compareJSON(expectedJson, actualJson, JSONCompareMode.STRICT_ORDER);
    // 检查比较结果
    if (result.failed()) { // 失败了就代表json有差异
        for (FieldComparisonFailure fieldFailure : result.getFieldFailures()) {
            System.out.println("匹配失败路径: " + fieldFailure.getField());
            System.out.println("期望值: " + fieldFailure.getExpected());
            System.out.println("实际值: " + fieldFailure.getActual());
            System.out.println("----------------------------------------");
        }
    }

输出的结果如下:
匹配失败路径: address.city
期望值: beijing
实际值: nanjing

匹配失败路径: age
期望值: 18
实际值: 20

没有检测出来hobby数组中对basketball -> pingpong值的修改

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions