Spring Boot – Example of RESTful Web Service with XML

In Previous post we have create spring boot restful web services json example .  Now we will create spring boot restful webservice with xml .  For this we need to add jackson-dataformat-xml dependency in pom file.


Note -> After add this dependency we will pass Accept header as application/xml then will get response in xml if we pass application/json then got response in json. 

Firstly we will make a get restful web service in spring boot for  this we will create UserController.java , one model User.java and add jackson-dataformat-xml dependency in pom.xml as below.


<?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.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 getUser(){
		User user = new  User();
		return user;


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;


Now run spring boot application and hit api in postman as





spring boot restful webservice with xml response
spring boot restful webservice with xml response
spring boot restful webservice with json response
spring boot restful web service with json response 

See full example How to create restful webservice in spring boot click here . Hope you enjoy this post.

Leave a Reply

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

52 − = 48