json-merge-patch

Implementation for Json Merge Patch based on RFC-7386

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.hubbledouble
ArtifactId

ArtifactId

json-merge-patch
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

json-merge-patch
Implementation for Json Merge Patch based on RFC-7386
Project URL

Project URL

https://github.com/hubbledouble/json-merge-patch
Source Code Management

Source Code Management

http://github.com/hubbledouble/json-merge-patch

Download json-merge-patch

How to add to project

<!-- https://jarcasting.com/artifacts/com.hubbledouble/json-merge-patch/ -->
<dependency>
    <groupId>com.hubbledouble</groupId>
    <artifactId>json-merge-patch</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.hubbledouble/json-merge-patch/
implementation 'com.hubbledouble:json-merge-patch:1.0.1'
// https://jarcasting.com/artifacts/com.hubbledouble/json-merge-patch/
implementation ("com.hubbledouble:json-merge-patch:1.0.1")
'com.hubbledouble:json-merge-patch:jar:1.0.1'
<dependency org="com.hubbledouble" name="json-merge-patch" rev="1.0.1">
  <artifact name="json-merge-patch" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.hubbledouble', module='json-merge-patch', version='1.0.1')
)
libraryDependencies += "com.hubbledouble" % "json-merge-patch" % "1.0.1"
[com.hubbledouble/json-merge-patch "1.0.1"]

Dependencies

compile (3)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-databind jar 2.9.9
org.hibernate.validator : hibernate-validator jar 6.0.14.Final
org.glassfish : javax.el jar 3.0.1-b09

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

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
    }
  }

Versions

Version
1.0.1
1.0.0