-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore difference between null or empty array #17
Comments
Hi @paulux84, I need a little bit refactoring on the library to be able to implement this feature easily, public class AdvancedJsonArrayMatcher implements JsonMatcher {
private final PartialJsonMatcher<ArrayNode> jsonArrayPartialMatcher;
private final PartialJsonMatcher<ObjectNode> jsonObjectPartialMatcher;
private final PartialJsonMatcher<ValueNode> primitivePartialMatcher;
public AdvancedJsonArrayMatcher(
PartialJsonMatcher<ArrayNode> jsonArrayPartialMatcher,
PartialJsonMatcher<ObjectNode> jsonObjectPartialMatcher,
PartialJsonMatcher<ValueNode> primitivePartialMatcher
) {
this.jsonArrayPartialMatcher = jsonArrayPartialMatcher;
this.jsonObjectPartialMatcher = jsonObjectPartialMatcher;
this.primitivePartialMatcher = primitivePartialMatcher;
}
@Override
public JsonDiff diff(Path path, JsonNode expected, JsonNode received) {
// check comparison between array and null values
if (
(expected.isEmpty() && received.isNull())
|| (received.isEmpty() && expected.isNull())
) {
return new MatchedPrimaryDiff(path, expected);
}
// default JsonMatcher code
if (expected instanceof ObjectNode && received instanceof ObjectNode) {
return this.jsonObjectPartialMatcher.jsonDiff(path, (ObjectNode) expected, (ObjectNode) received, this);
} else if (expected instanceof ArrayNode && received instanceof ArrayNode) {
return this.jsonArrayPartialMatcher.jsonDiff(path, (ArrayNode) expected, (ArrayNode) received, this);
} else if (expected instanceof ValueNode && received instanceof ValueNode){
return this.primitivePartialMatcher.jsonDiff(path, (ValueNode) expected, (ValueNode) received, this);
} else {
return new UnMatchedPrimaryDiff(path, expected, received);
}
}
} And you this class like you use the
and
This case il already covered by the To avoid to be able to implement custom |
Seems not working...i have nested arrays and are not working |
Can be usefull to add a the possibility in LenientJsonArrayPartialMatcher to ignore difference between null array, array field not exist or empty array.
So this three example become the same
{ name: "example" }
The text was updated successfully, but these errors were encountered: