Back to articles
JSON Patch in Java — Without Converting Everything to JsonNode

JSON Patch in Java — Without Converting Everything to JsonNode

via Dev.toYu Han

Partial updates are everywhere. Modern APIs frequently support HTTP PATCH , and JSON Patch (defined in RFC 6902) has become a standard way to describe structural changes to JSON documents. A typical patch looks like this: [ { "op" : "replace" , "path" : "/name" , "value" : "Alice Zhang" }, { "op" : "add" , "path" : "/scores/physics" , "value" : 91 } ] Conceptually, it’s simple: replace a value add a value remove something move something JSON Patch is elegant. But when using it in Java, things often become… slightly less elegant. The Usual Java Workflow Most JSON Patch libraries operate on JSON tree models. Which means your code typically looks like this: POJO ↓ JsonNode ↓ apply patch ↓ JsonNode ↓ POJO In practice this means: converting your objects into JSON trees applying the patch converting everything back This works, but it introduces extra layers and conversions that aren't really related to the domain model. A Different Approach Instead of operating on a JSON tree, SJF4J applies

Continue reading on Dev.to

Opens in a new tab

Read Full Article
3 views

Related Articles