Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<div style="text-align: center">


[![GitHub license](https://img.shields.io/github/license/codeleep/jsonDiff)](https://github.com/codeleep/jsonDiff/blob/master/LICENSE)
[![GitHub license](https://img.shields.io/github/license/codeleep/json-diff)](https://github.com/codeleep/json-diff/blob/master/LICENSE)
[![star](https://gitee.com/codeleep/json-diff/badge/star.svg?theme=white)](https://gitee.com/codeleep/json-diff/stargazers)
<a href='https://gitee.com/codeleep/json-diff/members'><img src='https://gitee.com/codeleep/json-diff/badge/fork.svg?theme=white' alt='fork'></img></a>
[![GitHub stars](https://img.shields.io/github/stars/codeleep/jsonDiff)](https://github.com/codeleep/jsonDiff/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/codeleep/jsonDiff)](https://github.com/codeleep/jsonDiff/network)
[![GitHub issues](https://img.shields.io/github/issues/codeleep/jsonDiff)](https://github.com/codeleep/jsonDiff/issues)
[![GitHub stars](https://img.shields.io/github/stars/codeleep/json-diff)](https://github.com/codeleep/json-diff/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/codeleep/json-diff)](https://github.com/codeleep/json-diff/network)
[![GitHub issues](https://img.shields.io/github/issues/codeleep/json-diff)](https://github.com/codeleep/json-diff/issues)

</div>

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Constant {
* 遍历所需常量
***************************************************************************
*/
public static final String PATH_ROOT = "root";
public static final String PATH_ROOT = "$";
public static final String SIGN = ".";
public static final String JOIN_SPILT = "@_^_@";
public static final String NULL = "null";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import me.codeleep.jsondiff.common.utils.PathUtil;

import static me.codeleep.jsondiff.common.model.Constant.PATH_ROOT;

/**
* @author: codeleep
* @createTime: 2023/03/05 01:33
Expand Down Expand Up @@ -35,7 +37,7 @@ public TravelPath(TravelPath parentPath, MappingKey mappingKey) {

public TravelPath(TravelPath parentPath, int expectIndex, int actualIndex) {
// 抽象的路径
this.abstractTravelPath = parentPath.getAbstractTravelPath() + PathUtil.getIndexPath("");
this.abstractTravelPath = parentPath.getAbstractTravelPath() + PathUtil.getIndexPath("*");
// 实际遍历的路径
this.actualTravelPath = parentPath.getActualTravelPath() + PathUtil.getIndexPath(String.valueOf(actualIndex));
this.expectTravelPath = parentPath.getExpectTravelPath() + PathUtil.getIndexPath(String.valueOf(expectIndex));
Expand All @@ -47,6 +49,12 @@ public TravelPath(String abstractTravelPath) {
this.expectTravelPath = abstractTravelPath;
}

public TravelPath() {
this.abstractTravelPath = PATH_ROOT;
this.actualTravelPath = PATH_ROOT;
this.expectTravelPath = PATH_ROOT;
}


public TravelPath(TravelPath travel) {
this.abstractTravelPath = travel.getAbstractTravelPath();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package me.codeleep.jsondiff.common.utils;


import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author: codeleep
* @createTime: 2023/02/20 17:39
Expand All @@ -21,35 +18,8 @@ public static String getIndexPath(String index) {
return ARRAY_SING_LEFT + index + ARRAY_SING_RIGHT;
}


public static String getObjectPath(String parentPath) {
return parentPath + OBJECT_SING;
}


/**
* 将下标填入path
* @param path 路径地址
* @param index 下标
* @return
*/
public static String insertPathIndex(String path, int index) {
if (path == null || path.length() == 0 || index < 0) {
return path;
}
// 正则表达式匹配"]["
Pattern pattern = Pattern.compile("\\]\\[");
Matcher matcher = pattern.matcher(new StringBuilder(path).reverse());
StringBuilder sb = new StringBuilder(path);
sb.reverse();
// 循环匹配"[]",并记录匹配到的最右边的位置
if (matcher.find()) {
// 记录第一个"[]"出现的位置
int i = matcher.start();
sb.insert(i + 1, index); // 在"[]"中间插入数字
}
return sb.reverse().toString();
return parentPath.replaceAll("\\[\\d+]", "[*]") + OBJECT_SING;
}


}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ private void keySetConversion(Set<String> expectKeys, Set<String> actualKeys) {
// 移除忽略的Path
HashSet<String> ignorePath = RunTimeDataFactory.getOptionInstance().getIgnorePath();
List<MappingKey> mappingKeys = keyMap.stream().filter(mappingKey -> {
String actualTravelPath = PathUtil.getObjectPath(travelPath.getAbstractTravelPath()) + mappingKey.getActualKey();
String expectTravelPath = PathUtil.getObjectPath(travelPath.getAbstractTravelPath()) + mappingKey.getActualKey();
String actualTravelPath = PathUtil.getObjectPath(travelPath.getActualTravelPath()) + mappingKey.getActualKey();
String expectTravelPath = PathUtil.getObjectPath(travelPath.getExpectTravelPath()) + mappingKey.getExpectKey();
if (ignorePath.contains(actualTravelPath) || ignorePath.contains(expectTravelPath) ) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion json-diff-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</dependency>
<dependency>
<groupId>cn.xiaoandcai</groupId>
<artifactId>json-diff-core</artifactId>
<artifactId>json-diff</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package me.codeleep.jsondiff.test;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import me.codeleep.jsondiff.core.DefaultJsonDifference;
import me.codeleep.jsondiff.DefaultJsonDifference;
import me.codeleep.jsondiff.common.model.JsonCompareResult;
import me.codeleep.jsondiff.core.config.JsonDiffOption;
import me.codeleep.jsondiff.impl.ImplType;
import me.codeleep.jsondiff.test.model.MetaData;
import me.codeleep.jsondiff.test.dataFactory.ArrayDataFactory;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.alibaba.fastjson2.JSON;
import me.codeleep.jsondiff.common.model.JsonCompareResult;
import me.codeleep.jsondiff.core.DefaultJsonDifference;
import me.codeleep.jsondiff.DefaultJsonDifference;
import me.codeleep.jsondiff.test.dataFactory.ObjectDataFactory;
import me.codeleep.jsondiff.test.model.MetaData;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package me.codeleep.jsondiff.core;
package me.codeleep.jsondiff;

import me.codeleep.jsondiff.common.exception.JsonDiffException;
import me.codeleep.jsondiff.common.model.JsonCompareResult;
import me.codeleep.jsondiff.core.config.JsonComparedOption;
import me.codeleep.jsondiff.common.model.TravelPath;
import me.codeleep.jsondiff.common.model.neat.JsonDiff;
import me.codeleep.jsondiff.common.model.neat.JsonNeat;
import me.codeleep.jsondiff.core.utils.RunTimeDataFactory;
import me.codeleep.jsondiff.core.config.JsonComparedOption;
import me.codeleep.jsondiff.core.utils.JsonDiffBuilder;

import static me.codeleep.jsondiff.common.model.Constant.PATH_ROOT;
import me.codeleep.jsondiff.core.utils.RunTimeDataFactory;

/**
* @author: codeleep
Expand All @@ -21,11 +19,13 @@ public class DefaultJsonDifference {
public JsonCompareResult detectDiff(String expect, String actual) {
JsonDiff expectJson = JsonDiffBuilder.buildObject(expect);
JsonDiff actualJson = JsonDiffBuilder.buildObject(actual);
return detectDiff(expectJson, actualJson);
}

TravelPath travelPath = new TravelPath(PATH_ROOT);
JsonNeat<? extends JsonDiff> jsonNeat = RunTimeDataFactory.getOptionInstance().getJsonNeatFactory().generate(actualJson, expectJson, travelPath);
public JsonCompareResult detectDiff(JsonDiff expect, JsonDiff actual) {
JsonNeat<? extends JsonDiff> jsonNeat = RunTimeDataFactory.getOptionInstance().getJsonNeatFactory().generate(expect, actual, new TravelPath());
if (jsonNeat == null) {
throw new JsonDiffException("无法找到适配比较器");
throw new JsonDiffException("Unable to find JsonNeat");
}
JsonCompareResult result = jsonNeat.diff();
// 清除设置
Expand Down