Spring MVC - Mapping JSON body data of HTTP PATCH request to Java Object

[Last Updated: Feb 23, 2018]

This tutorial shows how to handle JSON body data of HTTP PATCH request in Spring MVC.


The controller

public class ArticleController {

  private ArticleService articleService;

  public String patchArticle(@RequestBody Article article) {
      articleService.updateArticle(article.getId(), article.getContent());
      return "Article updated.";

  public String getArticle(@PathVariable("id") long id, Model model) {
      Article article = articleService.getArticleById(id);
      model.addAttribute("article", article);
      return "article-form";
public class Article {
  private long id;
  private String content;

  public Article() {

  public Article(int id, String content) { = id;
      this.content = content;

JSP Pages


    <script src=""></script>

<h3>HTTP PATCH request with JSON Body Example</h3>
<form id="article-form">
         id: <input type="text" name="id" value="${}" readonly>
    content: <input type="text" name="content" value="${article.content}">
                  <input type="submit" value="Submit">
<div id="result"></div>

            var form = $(this);
            var idVal = form.find('input[name="id"]').val();
            var contentVal = form.find('input[name="content"]').val();
            var url = 'http://localhost:8080/articles/'+idVal;
            var jsonString = JSON.stringify({id: idVal, content: contentVal});
                type : 'PATCH',
                url : url,
                contentType: 'application/json',
                data : jsonString,
                success : function(data, status, xhr){
                   //refresh the current page
                error: function(xhr, status, error){

Additional JSON dependency



Java Config

public class MyWebConfig implements WebMvcConfigurer {

  public void configureViewResolvers(ViewResolverRegistry registry) {
      registry.jsp("/WEB-INF/views/", ".jsp");


The output is same as the last example.

Example Project

Dependencies and Technologies Used:

  • spring-webmvc 5.0.3.RELEASE: Spring Web MVC.
  • jackson-databind 2.9.4: General data-binding functionality for Jackson: works on core streaming API.
  • javax.servlet-api 3.0.1 Java Servlet API
  • jstl 1.2 javax.servlet:jstl
  • JDK 1.8
  • Maven 3.3.9

HTTP JSON PATCH Request Example Select All Download
  • spring-patch-json-body-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • webapp
          • WEB-INF
            • views
              • article-form.jsp

    See Also