Newsletter

Spring Boot – Example of RESTful Web Service with XML Response

Spring boot services by default gives the response in JSON format, but we can reverse this functionality in such a way that the default response will be in XML.  In order to do that we have to add a new dependency called jackson-dataformat-xml.  With this dependency services by default gives the response in XML format and if you want to see the response in JSON, just append .json to the URL that’s it :-) I will show you with an example.

Dependency

Final pom.xml

SpringBootApp.java

application.properties

SpringJava4sController.java

Customer.java

Output

Run the application and hit http://localhost:8080/springbootrestxml/get-cust-info

If we want to see the response in JSON, append .json to the URL.. http://localhost:8080/springbootrestxml/get-cust-info.json

 

You Might Also Like

  ::. About the Author .::

Java4s_Author
- Full Stack Java/J2EE & UI Web Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

One Response to “Spring Boot – Example of RESTful Web Service with XML Response”
  1. arrchana says:

    Hi,

    Your blog is really good and useful. I'm learning the spring by using your blog only. I'm trying a task like read data from excel and stored into pojo whenever I hit a spring boot based REST API. Is that possible. give me some idea on that.

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Hibernate Spring Struts
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.