1

Hi I am using following libraries to generate merge patch difference.

<dependencies>
    <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    <dependency>
        <groupId>javax.json</groupId>
        <artifactId>javax.json-api</artifactId>
        <version>1.1</version>
    </dependency>


    <dependency>
        <groupId>org.apache.johnzon</groupId>
        <artifactId>johnzon-core</artifactId>
        <version>1.2.5</version>
    </dependency>

</dependencies>

Following are the source and target jsons. Source json

{
  "firstName": "Krishna",
  "lastName": "Gurram",
  "hobbies": [
    "Cricket",
    "Football"
  ],
  "address": {
    "city": "Bangalore",
    "state": "Karnataka",
    "country": "India"
  }
}

Target json

{
  "firstName": "Ram",
  "lastName": "Gurram",
  "hobbies": [
    "Football",
    "Chess"
  ],
  "address": {
    "city": "Amaravathi",
    "state": "Andhra Pradesh",
    "country": "India"
  }
}

I am using following snippet to get the merge patch between source and target json documents.

JsonValue sourceJsonValue = Json.createReader(new StringReader(sourceJson)).readValue();
JsonValue targetJsonValue = Json.createReader(new StringReader(targetJson)).readValue();
JsonMergePatch jsonMergePatch = Json.createMergeDiff(sourceJsonValue, targetJsonValue);

I end up with following error.

Exception in thread "main" java.lang.NullPointerException
    at org.apache.johnzon.core.JsonMergePatchDiff.diff(JsonMergePatchDiff.java:58)
    at org.apache.johnzon.core.JsonMergePatchDiff.calculateDiff(JsonMergePatchDiff.java:44)
    at org.apache.johnzon.core.JsonProviderImpl.createMergeDiff(JsonProviderImpl.java:226)
    at javax.json.Json.createMergeDiff(Json.java:427)
    at com.sample.app.App.main(App.java:57)

Am I using the apis in correct way to generate merge patch or am I missing anything?

Reference: https://www.rfc-editor.org/rfc/rfc7386

Community
  • 1
  • 1
Hari Krishna
  • 3,658
  • 1
  • 36
  • 57
  • 1
    Could reproduce, it seems that the constant `JsonValue.EMPTY_JSON_OBJECT` is `null` inside `JsonMergePatchDiff.diff()`. Could maybe be a bug in the library you're using, I'm not entirely sure though – Lino Mar 26 '21 at 07:23

0 Answers0