Jun
21.
Many of us use JSON almost exclusively now, which is generally a good thing. But what happens when you need to “speak XML” with your Spring Boot REST endpoints?
XML support in Spring Boot’s REST endpoints is not enabled by default, but adding it isn’t difficult at all. Simply add the following dependency to your POM (or similar entry to your Gradle build file, if that’s the way you roll) and rebuild:
Now, to test our results. To do so, I’m using the excellent httpie, with its shortcut that allows the omission of the hostname for localhost.
JSON
XML
Note that no changes are required to your code, as Spring Boot assesses your classpath and adds XML support via auto-configuration. Simple and painless! 🙂
Thanks for reading, be sure to follow me on Twitter for future tips!
Keep coding,
Mark
Related Posts:
Tags: dataformat, endpoint, Jackson, jackson-dataformat-xml, JSON, REST, Spring, Spring Boot, T4SD, Tips 4 Spring Devs, XML
[…] Mark Heckler looks at serving XML in REST APIs in this useful post […]
[…] How to get Spring Boot REST endpoints to speak XML […]