Skip to content

Instantly share code, notes, and snippets.

@bijukunjummen
Last active May 8, 2021 18:16
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/d4a080c3b7c5ce6eb8a716572ff6d86e to your computer and use it in GitHub Desktop.
Save bijukunjummen/d4a080c3b7c5ce6eb8a716572ff6d86e 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 = """
    [
        { "op": "replace", "path": "/title", "value": "Hello!"},
        { "op": "remove", "path": "/author/familyName"},
        { "op": "add", "path": "/phoneNumber", "value": "+01-123-456-7890"},
        { "op": "replace", "path": "/tags", "value": ["example"]}
    ]
""".trimIndent()
val jsonPatch: JsonPatch = JsonPatch.fromJson(objectMapper.readTree(patch))
val target = jsonPatch.apply(objectMapper.readTree(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment