Skip to content

Instantly share code, notes, and snippets.

@bijukunjummen
Created May 8, 2021 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bijukunjummen/13d99aed7898b817a04c542e0f6593c2 to your computer and use it in GitHub Desktop.
Save bijukunjummen/13d99aed7898b817a04c542e0f6593c2 to your computer and use it in GitHub Desktop.
val s = """
{
    "title": "Goodbye!",
    "author": {
      "givenName": "John",
      "familyName": "Doe"
    },
    "tags": [
      "example",
      "sample"
    ],
    "content": "This will be unchanged"
}       
""".trimIndent()
 
val patch = """
{
    "title": "Hello!",
    "author": {
      "familyName": null
    },
    "phoneNumber": "+01-123-456-7890",
    "tags": ["example"]
}  
""".trimIndent()
 
val jsonMergePatch: JsonMergePatch = JsonMergePatch.fromJson(objectMapper.readTree(patch))
val target = jsonMergePatch.apply(objectMapper.readTree(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment