Open imfms opened 11 months ago
{ "source": { "1": 1, "3": 4 }, "target": { "2": 4, "5": "asdf" }, "patch": [ { "op": "remove", "path": "/1" }, { "op": "move", "from": "/3", "path": "/1" // should be "path": "/2" }, { "op": "add", "path": "/5", "value": "asdf" } ], "patched": { "1": 4, // should be "2": 4 "5": "asdf" } }
mkdir -p test-case/src/test/java/com/example/test/ cd test-case (cat << "EOF" package com.example.test; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.zjsonpatch.JsonDiff; import com.flipkart.zjsonpatch.JsonPatch; import org.junit.Test; import java.util.LinkedHashMap; import java.util.Map; import static org.junit.Assert.assertEquals; public class TestJsonPatch { @Test public void testPatch() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); JsonNode source = objectMapper.valueToTree(Map.of( "1", 1, "3", 4 )); JsonNode target = objectMapper.valueToTree(Map.of( "2", 4, "5", "asdf" )); JsonNode patch = JsonDiff.asJson(source, target); JsonNode patched = JsonPatch.apply(patch, source); System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(new LinkedHashMap<>() {{ put("source", source); put("target", target); put("patch", patch); put("patched", patched); }})); assertEquals(target, patched); } } EOF )>src/test/java/com/example/test/TestJsonPatch.java (cat << "EOF" <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>test</artifactId> <version>0.0.1-SNAPSHOT</version> <name>test</name> <description>test</description> <properties> <java.version>11</java.version> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>com.flipkart.zjsonpatch</groupId> <artifactId>zjsonpatch</artifactId> <version>0.4.14</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> </dependencies> </project> EOF )>pom.xml mvn test
docker run -v $PWD/test-case.sh:/data/test-case.sh adoptopenjdk/maven-openjdk11 sh /data/test-case.sh
Mostly fails, occasionally succeeds
org.opentest4j.AssertionFailedError: Expected :{"5":"asdf","2":4} Actual :{"1":4,"5":"asdf"} { "source" : { "1" : 1, "3" : 4 }, "target" : { "5" : "asdf", "2" : 4 }, "patch" : [ { "op" : "remove", "path" : "/1" }, { "op" : "move", "from" : "/3", "path" : "/1" }, { "op" : "add", "path" : "/5", "value" : "asdf" } ], "patched" : { "1" : 4, "5" : "asdf" } }
It's probably the same as this issue #136
Specifications
Expected Behavior / Actual Behavior
Steps to Reproduce the Problem