{"id":73730,"date":"2018-02-21T13:00:53","date_gmt":"2018-02-21T11:00:53","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=73730"},"modified":"2018-02-21T10:39:10","modified_gmt":"2018-02-21T08:39:10","slug":"run-away-null-checks-feast-patch-properly-json-patch","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html","title":{"rendered":"Run away from &#8216;null&#8217; checks feast: doing PATCH properly with JSON Patch"},"content":{"rendered":"<p>Today we are going to have a conversation about <a href=\"https:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\">REST(ful) services<\/a> and APIs, more precisely, around one peculiar subject many experienced developers are struggling with. To put things into perspective, we are going to talk about web APIs, where the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\">REST(ful) principles<\/a> adhere to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">HTTP<\/a> protocol and heavily exploit the semantics of <a href=\"https:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec9.html\">HTTP methods<\/a> and (usually but not necessarily) use <a href=\"https:\/\/www.json.org\/\">JSON<\/a> to represent the state.<\/p>\n<p>One particular <a href=\"https:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec9.html\">HTTP method<\/a> stands out, and although its meaning sounds pretty straightforward, the implementation is far from that. Yes, we are looking at you, the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Patch_verb\">PATCH<\/a>. So what is the problem, really? It is just an update, right? Yes, in the essence the semantics of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Patch_verb\">PATCH<\/a> method in the context of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">HTTP<\/a>-based <a href=\"https:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\">REST(ful) web services<\/a> is partial update of the resource. Now, how would you do that, Java developer? Here is where the fun begins.<\/p>\n<p>Let us go over a very simple example of book management API, modeled using latest <a href=\"https:\/\/www.jcp.org\/en\/jsr\/detail?id=370\">JSR 370: Java API for RESTful Web Services (JAX-RS 2.1)<\/a> specification (which finally includes the <a href=\"https:\/\/javaee.github.io\/javaee-spec\/javadocs\/javax\/ws\/rs\/PATCH.html\">@PATCH<\/a> annotation!) and terrific <a href=\"http:\/\/cxf.apache.org\/download.html\">Apache CXF<\/a> framework. Our resource is just a very simplistic <b>Book<\/b> class.<\/p>\n<pre class=\"brush:java\">public class Book {\r\n    private String title;\r\n    private Collection&gt;String&lt; authors;\r\n    private String isbn;\r\n}<\/pre>\n<p>How would you implement the partial update using the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Patch_verb\">PATCH<\/a> method? Sadly, the brute force solution, the <code>null<\/code> feast, is the clear winner here.<\/p>\n<pre class=\"brush:java\">@PATCH\r\n@Path(\"\/{isbn}\")\r\n@Consumes(MediaType.APPLICATION_JSON)\r\npublic void update(@PathParam(\"isbn\") String isbn, Book book) {\r\n    final Book existing = bookService.find(isbn).orElseThrow(NotFoundException::new);\r\n        \r\n    if (book.getTitle() != null) {\r\n        existing.setTitle(book.getTitle());\r\n    }\r\n\r\n    if (book.getAuthors() != null) {\r\n        existing.setAuthors(book.getAuthors());\r\n    }\r\n        \r\n    \/\/ And here it goes on and on ...\r\n    \/\/ ...\r\n}<\/pre>\n<p>In the nutshell, this is null-guarded <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">PUT<\/a> clone. Probably, someone could claim that it kind of works and declare the victory here. But hopefully for majority of us this approach clearly has a lot of flaws and should be never taken. Alternatives? Yes, absolutely, <a href=\"https:\/\/tools.ietf.org\/html\/rfc6902\">RFC-6902: JSON Patch<\/a>, not an official standard just yet but it is getting there.<\/p>\n<p>The <a href=\"https:\/\/tools.ietf.org\/html\/rfc6902\">RFC-6902: JSON Patch<\/a> drastically changes the game by expressing a sequence of operations to apply to a <a href=\"https:\/\/www.json.org\/\">JSON<\/a> document. To illustrate the idea in action, let us start from a simple example of changing book&#8217;s title, described in the terms of desired outcome.<\/p>\n<pre class=\"brush:xml\">{ \"op\": \"replace\", \"path\": \"\/title\", \"value\": \"...\" }<\/pre>\n<p>Looks clean, what about adding the authors? Easy &#8230;<\/p>\n<pre class=\"brush:xml\">{ \"op\": \"add\", \"path\": \"\/authors\", \"value\": [\"...\", \"...\"] }<\/pre>\n<p>Awesome, sold out, but &#8230; implementation-wise it seems to require quite a lot of work, isn&#8217;t it? Not really if we rely on the latest and greatest <a href=\"https:\/\/www.jcp.org\/en\/jsr\/detail?id=374\">JSR 374: Java API for JSON Processing 1.1<\/a> which fully supports <a href=\"https:\/\/tools.ietf.org\/html\/rfc6902\">RFC-6902: JSON Patch<\/a>. Armed with the right tools, this time let us do it right.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:xml\">org.glassfish\r\n    javax.json\r\n    1.1.2<\/pre>\n<p>Interestingly, not many are aware of that <a href=\"http:\/\/cxf.apache.org\/download.html\">Apache CXF<\/a>, and in general any <a href=\"https:\/\/www.jcp.org\/en\/jsr\/detail?id=370\">JAX-RS<\/a>-complaint framework, closely integrates with <a href=\"https:\/\/www.jcp.org\/en\/jsr\/detail?id=374\">JSON-P<\/a> and supports its basic data types. In case of <a href=\"http:\/\/cxf.apache.org\/download.html\">Apache CXF<\/a>, it is just a matter of adding <code>cxf-rt-rs-extension-providers<\/code> module dependency:<\/p>\n<pre class=\"brush:xml\">org.apache.cxf\r\n    cxf-rt-rs-extension-providers\r\n    3.2.2<\/pre>\n<p>And registering <a href=\"https:\/\/cxf.apache.org\/javadoc\/latest\/org\/apache\/cxf\/jaxrs\/provider\/jsrjsonp\/JsrJsonpProvider.html\">JsrJsonpProvider<\/a> with your server factory bean, for example:<\/p>\n<pre class=\"brush:java\">@Configuration\r\npublic class AppConfig {\r\n    @Bean\r\n    public Server rsServer(Bus bus, BookRestService service) {\r\n        JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();\r\n        endpoint.setBus(bus);\r\n        endpoint.setAddress(\"\/\");\r\n        endpoint.setServiceBean(service);\r\n        endpoint.setProvider(new JsrJsonpProvider());\r\n        return endpoint.create();\r\n    }\r\n}<\/pre>\n<p>With all the pieces wired together, our <a href=\"https:\/\/en.wikipedia.org\/wiki\/Patch_verb\">PATCH<\/a> operation could be implemented using <a href=\"https:\/\/www.jcp.org\/en\/jsr\/detail?id=374\">JSR 374: Java API for JSON Processing 1.1<\/a> alone, in just a few lines:<\/p>\n<pre class=\"brush:java\">@Service\r\n@Path(\"\/catalog\")\r\npublic class BookRestService {\r\n    @Inject private BookService bookService;\r\n    @Inject private BookConverter converter;\r\n\r\n    @PATCH\r\n    @Path(\"\/{isbn}\")\r\n    @Consumes(MediaType.APPLICATION_JSON)\r\n    public void apply(@PathParam(\"isbn\") String isbn, JsonArray operations) {\r\n        final Book book = bookService.find(isbn).orElseThrow(NotFoundException::new);\r\n        final JsonPatch patch = Json.createPatch(operations);\r\n        final JsonObject result = patch.apply(converter.toJson(book));\r\n        bookService.update(isbn, converter.fromJson(result));\r\n    }\r\n}<\/pre>\n<p>The <b>BookConverter<\/b> performs the conversion between <b>Book<\/b> class and its <a href=\"https:\/\/www.json.org\/\">JSON<\/a> representation (and vise versa), which we are doing by hand to illustrate another capabilities which <a href=\"https:\/\/www.jcp.org\/en\/jsr\/detail?id=374\">JSR 374: Java API for JSON Processing 1.1<\/a> provides.<\/p>\n<pre class=\"brush:java\">@Component\r\npublic class BookConverter {\r\n    public Book fromJson(JsonObject json) {\r\n        final Book book = new Book();\r\n        book.setTitle(json.getString(\"title\"));\r\n        book.setIsbn(json.getString(\"isbn\"));\r\n        book.setAuthors(\r\n            json\r\n                .getJsonArray(\"authors\")\r\n                .stream()\r\n                .map(value -&gt; (JsonString)value)\r\n                .map(JsonString::getString)\r\n                .collect(Collectors.toList()));\r\n        return book;\r\n    }\r\n\r\n    public JsonObject toJson(Book book) {\r\n        return Json\r\n            .createObjectBuilder()\r\n            .add(\"title\", book.getTitle())\r\n            .add(\"isbn\", book.getIsbn())\r\n            .add(\"authors\", Json.createArrayBuilder(book.getAuthors()))\r\n            .build();\r\n    }\r\n}<\/pre>\n<p>To finish up, let is wrap this simple <a href=\"https:\/\/www.jcp.org\/en\/jsr\/detail?id=370\">JAX-RS 2.1<\/a> web API into the beautiful <a href=\"https:\/\/projects.spring.io\/spring-boot\/\">Spring Boot<\/a> envelope.<\/p>\n<pre class=\"brush:java\">@SpringBootApplication\r\npublic class BookServerStarter {    \r\n    public static void main(String[] args) {\r\n        SpringApplication.run(BookServerStarter.class, args);\r\n    }\r\n}<\/pre>\n<p>And run it.<\/p>\n<pre class=\"brush:java\">mvn spring-boot:run<\/pre>\n<p>To conclude the discussion, let us play a bit with more realistic examples by deliberately adding an <a href=\"https:\/\/www.amazon.com\/Microservice-Architecture-Aligning-Principles-Practices\/dp\/1491956259\">incomplete book<\/a> into our catalog.<\/p>\n<pre class=\"brush:java\">$ curl -i -X POST http:\/\/localhost:19091\/services\/catalog -H \"Content-Type: application\\json\" -d '{\r\n       \"title\": \"Microservice Architecture\",\r\n       \"isbn\": \"978-1491956250\",\r\n       \"authors\": [\r\n           \"Ronnie Mitra\",\r\n           \"Matt McLarty\"\r\n       ]\r\n   }'\r\n\r\nHTTP\/1.1 201 Created\r\nDate: Tue, 20 Feb 2018 02:30:18 GMT\r\nLocation: http:\/\/localhost:19091\/services\/catalog\/978-1491956250\r\nContent-Length: 0<\/pre>\n<p>There are a couple of inaccuracies we would like to fix in this book description, namely set the title to be complete, <b>&#8220;Microservice Architecture: Aligning Principles, Practices, and Culture&#8221;<\/b>, and include missing co-authors, <b>Irakli Nadareishvili<\/b> and <b>Mike Amundsen<\/b>. With the API we have developed a moment ago, it is a no-brainer.<\/p>\n<pre class=\"brush:java\">$ curl -i -X PATCH http:\/\/localhost:19091\/services\/catalog\/978-1491956250 -H \"Content-Type: application\\json\" -d '[\r\n       { \"op\": \"add\", \"path\": \"\/authors\/0\", \"value\": \"Irakli Nadareishvili\" },\r\n       { \"op\": \"add\", \"path\": \"\/authors\/-\", \"value\": \"Mike Amundsen\" },\r\n       { \"op\": \"replace\", \"path\": \"\/title\", \"value\": \"Microservice Architecture: Aligning Principles, Practices, and Culture\" }\r\n   ]'\r\n\r\nHTTP\/1.1 204 No Content\r\nDate: Tue, 20 Feb 2018 02:38:48 GMT<\/pre>\n<p>The path reference of the first two operations may look confusing a bit but fear no more, let us clarify that. Because <code>authors<\/code> is a collection (or in terms of <a href=\"https:\/\/www.json.org\/\">JSON<\/a> data types, an array) we could use <a href=\"https:\/\/tools.ietf.org\/html\/rfc6902\">RFC-6902: JSON Patch<\/a> array index notation to specify exactly where we would like the new element to be inserted. The first operations uses index <code>'0'<\/code> to denote the head position, while the second one uses <code>'-'<\/code> placeholder to simplify say &#8220;add to the end of the collection&#8221;. If we retrieve the book right after the update, we should see our modifications to be applied exactly as we asked.<\/p>\n<pre class=\"brush:java\">$ curl http:\/\/localhost:19091\/services\/catalog\/978-1491956250\r\n\r\n{\r\n    \"title\": \"Microservice Architecture: Aligning Principles, Practices, and Culture\",\r\n    \"isbn\": \"978-1491956250\",\r\n    \"authors\": [\r\n        \"Irakli Nadareishvili\",\r\n        \"Ronnie Mitra\",\r\n        \"Matt McLarty\",\r\n        \"Mike Amundsen\"\r\n    ]\r\n}<\/pre>\n<p>Clean, simple and powerful. To be fair, there is a price to pay is a form of additional <a href=\"https:\/\/www.json.org\/\">JSON<\/a> manipulations (in order to apply the patch) but is it worth the effort? I believe it is &#8230;<\/p>\n<p>Next time you are going to design new shiny <a href=\"https:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\">REST(ful) web APIs<\/a>, please seriously consider <a href=\"https:\/\/tools.ietf.org\/html\/rfc6902\">RFC-6902: JSON Patch<\/a> to back the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Patch_verb\">PATCH<\/a> implementation of your resources. I believe more close integration with <a href=\"https:\/\/www.jcp.org\/en\/jsr\/detail?id=370\">JAX-RS<\/a> is also coming (if not there yet) to directly support <a href=\"https:\/\/javaee.github.io\/javaee-spec\/javadocs\/javax\/json\/JsonPatch.html\">JSONPatch<\/a> class and its family.<\/p>\n<p>And last, but not least, in this post we have touched on server-side implementation only, but <a href=\"https:\/\/www.jcp.org\/en\/jsr\/detail?id=374\">JSR 374: Java API for JSON Processing 1.1<\/a> includes convenient client-side scaffolding as well, giving full-fledged programmatic control over the patches.<\/p>\n<pre class=\"brush:java\">final JsonPatch patch = Json.createPatchBuilder()\r\n    .add(\"\/authors\/0\", \"Irakli Nadareishvili\")\r\n    .add(\"\/authors\/-\", \"Mike Amundsen\")\r\n    .replace(\"\/title\", \"Microservice Architecture: Aligning Principles, Practices, and Culture\")\r\n    .build();<\/pre>\n<p>The complete project sources are available on <a href=\"https:\/\/github.com\/reta\/jax-rs-2.1-json-patch\">Github<\/a>.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on Java Code Geeks with permission by Andrey Redko, partner at our <a href=\"http:\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"http:\/\/aredko.blogspot.com\/2018\/02\/run-away-from-null-checks-feast-doing.html\" target=\"_blank\" rel=\"noopener\">Run away from &#8216;null&#8217; checks feast: doing PATCH properly with JSON Patch (RFC-6902)<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today we are going to have a conversation about REST(ful) services and APIs, more precisely, around one peculiar subject many experienced developers are struggling with. To put things into perspective, we are going to talk about web APIs, where the REST(ful) principles adhere to HTTP protocol and heavily exploit the semantics of HTTP methods and &hellip;<\/p>\n","protected":false},"author":141,"featured_media":175,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[439,69,1683,854],"class_list":["post-73730","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jax-rs","tag-json","tag-json-patch","tag-spring-boot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Run away from &#039;null&#039; checks feast: doing PATCH properly with JSON Patch - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Today we are going to have a conversation about REST(ful) services and APIs, more precisely, around one peculiar subject many experienced developers are\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Run away from &#039;null&#039; checks feast: doing PATCH properly with JSON Patch - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Today we are going to have a conversation about REST(ful) services and APIs, more precisely, around one peculiar subject many experienced developers are\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-21T11:00:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andrey Redko\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrey Redko\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html\"},\"author\":{\"name\":\"Andrey Redko\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/771a6504862edc45322776832cbce413\"},\"headline\":\"Run away from &#8216;null&#8217; checks feast: doing PATCH properly with JSON Patch\",\"datePublished\":\"2018-02-21T11:00:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html\"},\"wordCount\":861,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"keywords\":[\"JAX-RS\",\"JSON\",\"json patch\",\"Spring Boot\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html\",\"name\":\"Run away from 'null' checks feast: doing PATCH properly with JSON Patch - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"datePublished\":\"2018-02-21T11:00:53+00:00\",\"description\":\"Today we are going to have a conversation about REST(ful) services and APIs, more precisely, around one peculiar subject many experienced developers are\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/run-away-null-checks-feast-patch-properly-json-patch.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Run away from &#8216;null&#8217; checks feast: doing PATCH properly with JSON Patch\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/771a6504862edc45322776832cbce413\",\"name\":\"Andrey Redko\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g\",\"caption\":\"Andrey Redko\"},\"description\":\"Andriy is a well-grounded software developer with more then 12 years of practical experience using Java\\\/EE, C#\\\/.NET, C++, Groovy, Ruby, functional programming (Scala), databases (MySQL, PostgreSQL, Oracle) and NoSQL solutions (MongoDB, Redis).\",\"sameAs\":[\"http:\\\/\\\/aredko.blogspot.com\\\/\",\"http:\\\/\\\/ca.linkedin.com\\\/in\\\/aredko\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/andrey-redko\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Run away from 'null' checks feast: doing PATCH properly with JSON Patch - Java Code Geeks","description":"Today we are going to have a conversation about REST(ful) services and APIs, more precisely, around one peculiar subject many experienced developers are","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html","og_locale":"en_US","og_type":"article","og_title":"Run away from 'null' checks feast: doing PATCH properly with JSON Patch - Java Code Geeks","og_description":"Today we are going to have a conversation about REST(ful) services and APIs, more precisely, around one peculiar subject many experienced developers are","og_url":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-02-21T11:00:53+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","type":"image\/jpeg"}],"author":"Andrey Redko","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Andrey Redko","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html"},"author":{"name":"Andrey Redko","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/771a6504862edc45322776832cbce413"},"headline":"Run away from &#8216;null&#8217; checks feast: doing PATCH properly with JSON Patch","datePublished":"2018-02-21T11:00:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html"},"wordCount":861,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","keywords":["JAX-RS","JSON","json patch","Spring Boot"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html","url":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html","name":"Run away from 'null' checks feast: doing PATCH properly with JSON Patch - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","datePublished":"2018-02-21T11:00:53+00:00","description":"Today we are going to have a conversation about REST(ful) services and APIs, more precisely, around one peculiar subject many experienced developers are","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/run-away-null-checks-feast-patch-properly-json-patch.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Run away from &#8216;null&#8217; checks feast: doing PATCH properly with JSON Patch"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/771a6504862edc45322776832cbce413","name":"Andrey Redko","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g","caption":"Andrey Redko"},"description":"Andriy is a well-grounded software developer with more then 12 years of practical experience using Java\/EE, C#\/.NET, C++, Groovy, Ruby, functional programming (Scala), databases (MySQL, PostgreSQL, Oracle) and NoSQL solutions (MongoDB, Redis).","sameAs":["http:\/\/aredko.blogspot.com\/","http:\/\/ca.linkedin.com\/in\/aredko"],"url":"https:\/\/www.javacodegeeks.com\/author\/andrey-redko"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/73730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/141"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=73730"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/73730\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/175"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=73730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=73730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=73730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}