Spring Boot – RESTful Web Service with POST Request in XML Example

In this post we will create RESTful Web Service with POST Request in XML . If you are new in spring boot then firstly read this post How to create restful web service in spring boot . Now if you want to handle xml request and response in spring boot then you must add jackson-dataformat-xml  dependency in pom.xml .


Now we will create UserController.java with restful web service with post request you can read spring boot tutorial step by step spring boot tutorial  and User.java model class and will update pom.xml with jackson-dataformat-xml dependency . Now we will createspring boot rest xml request body example.


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
		<!-- <version>2.2.6.RELEASE</version> -->
	<!-- 	<relativePath/> --> <!-- lookup parent from repository -->
	<description>Demo project for Spring Boot</description>







package com.javavogue.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class DemoApplication {
	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);



package com.javavogue.demo.model;

public class User {
	private int userId;
	private String name;
	public int getUserId() {
		return userId;
	public void setUserId(int userId) {
		this.userId = userId;
	public String getName() {
		return name;
	public void setName(String name) {
		this.name = name;




package com.javavogue.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.javavogue.demo.model.User;

public class UserController {
	public User addUser(@RequestBody User user){
		System.out.println("Add user successfully");
		user.setName("name ="+ user.getName());
		return user;

Now we will send xml request and got xml response from spring boot application as. Set header as per below .


Now send xml request as below



Leave a Reply

Your email address will not be published. Required fields are marked *

− 2 = 1