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

[Last Updated: Feb 22, 2018]

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


The controller

public class ArticleController {

  private ArticleService articleService;

  public String getArticleForm() {
      return "article-form";

  public String createNewArticle(@RequestBody Article article) {
      return "Article created.";

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

JSP Pages


    <script src=""></script>

<h3>HTTP PUT request with JSON Body Example</h3>
<form id="article-form">
         id: <input type="text" name="id">
    content: <input type="text" name="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 : 'PUT',
                url : url,
                contentType: 'application/json',
                data : jsonString,
                success : function(data, status, xhr){
                   " link: <a href='"+url+"'>"+url+"</a>");
                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");


To try examples, run embedded tomcat (configured in pom.xml of example project below):

mvn tomcat7:run-war

Accessing http://localhost:8080/articles:

Filling up and submitting the form:

In Chrome's developer tools window, we will see the logs:

Clicking on the hyper link of the article:

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

Spring Http Put Json Request Example Select All Download
  • spring-put-json-body-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • webapp
          • WEB-INF
            • views
              • article-form.jsp

    See Also