Skip to content

Commit

Permalink
fix : Add io.fabric8.zjsonpatch.Json* classes for backward compatib…
Browse files Browse the repository at this point in the history
…ility

After migrating to upstream zjsonpatch dependency,
KubernetesMutationHookHandlingTest started failing. Upon checking the
failures I found that this module depends on Java Operator SDK that also
uses zjsonpatch library to calculate JSON diff from KubernetesClient.

Adding back the `io.fabric8.zjsonpatch.JsonDiff` and
`io.fabric8.zjsonpatch.JsonPatch` classes.

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Aug 16, 2024
1 parent 23f3ea0 commit ee93287
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions zjsonpatch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*
</osgi.import>
<osgi.export>
io.fabric8.zjsonpatch,
com.flipkart.zjsonpatch,
org.apache.commons.collections4*
</osgi.export>
Expand Down
27 changes: 27 additions & 0 deletions zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonDiff.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.zjsonpatch;

import com.fasterxml.jackson.databind.JsonNode;

public class JsonDiff {
private JsonDiff() {
}

public static JsonNode asJson(final JsonNode source, final JsonNode target) {
return com.flipkart.zjsonpatch.JsonDiff.asJson(source, target);
}
}
45 changes: 45 additions & 0 deletions zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonPatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.zjsonpatch;

import com.fasterxml.jackson.databind.JsonNode;
import com.flipkart.zjsonpatch.CompatibilityFlags;
import com.flipkart.zjsonpatch.InvalidJsonPatchException;
import com.flipkart.zjsonpatch.JsonPatchApplicationException;

import java.util.EnumSet;

public class JsonPatch {
private JsonPatch() {
}

public static void validate(JsonNode patch, EnumSet<CompatibilityFlags> flags) throws InvalidJsonPatchException {
com.flipkart.zjsonpatch.JsonPatch.validate(patch, flags);
}

public static void validate(JsonNode patch) throws InvalidJsonPatchException {
com.flipkart.zjsonpatch.JsonPatch.validate(patch, CompatibilityFlags.defaults());
}

public static JsonNode apply(JsonNode patch, JsonNode source, EnumSet<CompatibilityFlags> flags)
throws JsonPatchApplicationException {
return com.flipkart.zjsonpatch.JsonPatch.apply(patch, source, flags);
}

public static JsonNode apply(JsonNode patch, JsonNode source) throws JsonPatchApplicationException {
return apply(patch, source, CompatibilityFlags.defaults());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* Commons Collections</a>
*/
public class ListUtils {
private ListUtils() {
}

/**
* Returns the longest common subsequence (LCS) of two sequences (lists).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.flipkart.zjsonpatch.JsonDiff;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand Down

0 comments on commit ee93287

Please sign in to comment.