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.
<dependency>
<groupId>com.hubbledouble</groupId>
<artifactId>json-merge-patch</artifactId>
<version>1.0.1</version>
</dependency>
public T patch(String json, String pathParamId){
T object = repository.findById(pathParamId);
HTTPMethodProcessor.patch(json, object);
repository.save(object);
}
{
"object" : "object",
"string" : "value",
"integer" : 1,
"child_object" : {
"object" : "other_object",
"string" : "other_value",
"integer" : 2
}
}
{
"child_object" : {
"object" : 5,
"string" : "updated_value"
}
}
{
"object" : "object",
"string" : "value",
"integer" : 1,
"child_object" : {
"object" : 5,
"string" : "updated_value",
"integer" : 2
}
}