Skip to content

Latest commit

 

History

History
67 lines (59 loc) · 1.58 KB

README.md

File metadata and controls

67 lines (59 loc) · 1.58 KB

Java JSON Merge patch implementation as per RFC-7386

Java specification implementation
The library provides a single point of entry for patching an object:
HTTPMethodProcessor#patch(String jsonRequest, T object) where "jsonRequest" is a partial json request and "object" is a the object to be patched.

Import the following library

   <dependency>
       <groupId>com.hubbledouble</groupId>
       <artifactId>json-merge-patch</artifactId>
       <version>1.0.1</version>
   </dependency>

Java usage example

 public T patch(String json, String pathParamId){
    T object = repository.findById(pathParamId);
    HTTPMethodProcessor.patch(json, object);
    repository.save(object);
 }

Data representation going through a merge patch update

Sample data (Original state)

  {
    "object"       : "object",
    "string"       : "value",
    "integer"      : 1,
    "child_object" : {
          "object"       : "other_object",
          "string"       : "other_value",
          "integer"      : 2
    }
  }

Sample patch request (only updating 2 fields of "child_object")

  {
    "child_object" : {
          "object"       : 5,
          "string"      : "updated_value"
    }
  }

Updated object (Only 2 fields were updated)

  {
    "object"       : "object",
    "string"       : "value",
    "integer"      : 1,
    "child_object" : {
          "object"       : 5,
          "string"       : "updated_value",
          "integer"      : 2
    }
  }