{"id":139901,"date":"2025-12-18T10:15:00","date_gmt":"2025-12-18T08:15:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=139901"},"modified":"2025-12-17T18:13:21","modified_gmt":"2025-12-17T16:13:21","slug":"posting-xml-data-with-spring-resttemplate","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html","title":{"rendered":"Posting XML Data with Spring RestTemplate"},"content":{"rendered":"<p>In modern microservice architectures, applications frequently communicate with external systems using REST APIs. While JSON is the most commonly used communication format, many enterprise systems such as banking, aviation, telecom, and legacy SOAP-based services still expect data in XML.  Spring Boot provides a convenient way to send XML data using <code>RestTemplate<\/code>, allowing developers to serialize Java objects into XML and send them via HTTP POST requests. Let us delve into understanding how Spring RestTemplate XML POST requests work.<\/p>\n<h2><a name=\"section-1\"><\/a>1. What is RestTemplate?<\/h2>\n<p><a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/javadoc-api\/org\/springframework\/web\/client\/RestTemplate.html\" target=\"_target\">RestTemplate<\/a> is a synchronous, blocking HTTP client provided by the Spring Framework. It is designed to make it easy for applications to communicate with RESTful services by abstracting away much of the underlying HTTP handling. Instead of manually constructing HTTP connections, writing XML\/JSON serialization code, or managing connection streams, developers can rely on RestTemplate\u2019s clean and intuitive API.<\/p>\n<p>Even though <em>RestTemplate is now in maintenance mode<\/em> (with <code>WebClient<\/code> being the recommended successor in reactive environments), it remains extremely popular and widely used in enterprise applications, especially those that require:<\/p>\n<ul>\n<li>Simple synchronous HTTP calls<\/li>\n<li>XML-based communication with legacy systems<\/li>\n<li>Straightforward request\/response patterns<\/li>\n<li>Integration with non-reactive Spring MVC applications<\/li>\n<\/ul>\n<p>RestTemplate offers a wide set of methods to perform CRUD operations against HTTP endpoints. Some of the commonly used methods include:<\/p>\n<ul>\n<li><code>postForObject(url, request, responseType)<\/code> \u2013 Sends a POST request and returns the response body as an object.<\/li>\n<li><code>postForEntity(url, request, responseType)<\/code> \u2013 Similar to <code>postForObject()<\/code> but includes full HTTP response details (status, headers, body).<\/li>\n<li><code>exchange(url, method, requestEntity, responseType)<\/code> \u2013 A more flexible method that supports custom headers, HTTP methods, and request\/response handling.<\/li>\n<\/ul>\n<p>Under the hood, RestTemplate uses HttpMessageConverters to automatically convert Java objects to and from various media types (JSON, XML, form data, plain text). When XML support is enabled using JAXB or Jackson XML, RestTemplate can seamlessly serialize Java POJOs into XML payloads and send them as part of an HTTP request.<\/p>\n<p>Because of its simplicity, predictability, and well-established usage patterns, <code>RestTemplate<\/code> continues to be an excellent choice for:<\/p>\n<ul>\n<li>Calling external APIs from backend systems<\/li>\n<li>Automating integration tasks<\/li>\n<li>Inter-service communication within traditional microservices<\/li>\n<li>Sending and receiving XML in enterprise workflows<\/li>\n<\/ul>\n<p>In summary, <code>RestTemplate<\/code> is a powerful yet easy-to-use tool for synchronous REST interactions. It hides the complexity of HTTP, letting developers focus on business logic rather than networking details.<\/p>\n<h2><a name=\"section-2\"><\/a>2. Code Example<\/h2>\n<h3>2.1 Adding Dependencies (pom.xml)<\/h3>\n<p>To enable XML serialization and HTTP communication using <code>RestTemplate<\/code>, add the following essential Spring Boot dependencies to your project\u2019s <code>pom.xml<\/code>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">\n&lt;dependencies&gt;\n    &lt;!-- Spring Web for RestTemplate --&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n\n    &lt;!-- JAXB for XML serialization --&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-starter-xml&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n&lt;\/dependencies&gt;\n<\/pre>\n<p>In this configuration, the <code>spring-boot-starter-web<\/code> dependency provides the required HTTP client support, including <code>RestTemplate<\/code>, while <code>spring-boot-starter-xml<\/code> activates JAXB-based XML marshalling and unmarshalling. Together, they allow Spring to automatically convert Java objects into XML payloads and seamlessly send them in HTTP requests.<\/p>\n<h3>2.2 XML DTO<\/h3>\n<p>The following Java class represents the XML payload model. It uses JAXB annotations to map Java fields to XML elements, allowing Spring to automatically convert the object into a well-structured XML document during the POST request.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\/\/ FlightRequest.java\nimport jakarta.xml.bind.annotation.XmlElement;\nimport jakarta.xml.bind.annotation.XmlRootElement;\n\n@XmlRootElement(name = \"FlightRequest\")\npublic class FlightRequest {\n\n    private String code;\n\n    public FlightRequest() {}\n    public FlightRequest(String code) { this.code = code; }\n\n    @XmlElement(name = \"FlightCode\")\n    public String getCode() { return code; }\n    public void setCode(String code) { this.code = code; }\n}\n<\/pre>\n<p>This class defines a simple XML structure where <code>FlightRequest<\/code> becomes the root tag and <code>FlightCode<\/code> represents a single nested element. The <code>@XmlRootElement<\/code> annotation tells Spring how to wrap the XML, while <code>@XmlElement<\/code> ensures that the <code>code<\/code> field is correctly serialized into the <code>&lt;FlightCode&gt;<\/code> tag when sending the HTTP POST request.<\/p>\n<h3>2.3 Simple Server Component to Receive XML POST<\/h3>\n<p>To demonstrate the complete end-to-end flow, let us create a very simple Spring Boot server component that receives the XML POST request and logs its contents. This helps verify that the XML sent by <code>RestTemplate<\/code> is correctly serialized, transmitted, and deserialized on the server side. The following REST controller exposes a POST endpoint that consumes XML, automatically converts it into the <code>FlightRequest<\/code> object, and logs the received payload.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\/\/ FlightController.java\nimport org.springframework.http.MediaType;\nimport org.springframework.web.bind.annotation.PostMapping;\nimport org.springframework.web.bind.annotation.RequestBody;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\npublic class FlightController {\n\n    @PostMapping(\n        value = \"\/api\/flights\",\n        consumes = MediaType.APPLICATION_XML_VALUE,\n        produces = MediaType.TEXT_PLAIN_VALUE\n    )\n    public String receiveFlight(@RequestBody FlightRequest request) {\n\n        System.out.println(\"Received XML Request\");\n        System.out.println(\"Flight Code: \" + request.getCode());\n\n        return \"Flight request received successfully\";\n    }\n}\n<\/pre>\n<h3>2.4 Main Class<\/h3>\n<p>The following Spring Boot class uses <code>CommandLineRunner<\/code> to automatically send an XML-based POST request as soon as the application starts. This design is useful for testing integrations, running startup processes, or triggering background workflows without requiring a controller endpoint.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\/\/ XmlPostApp.java\nimport org.springframework.boot.CommandLineRunner;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.http.HttpEntity;\nimport org.springframework.http.HttpHeaders;\nimport org.springframework.http.MediaType;\nimport org.springframework.web.client.RestTemplate;\n\n@SpringBootApplication\npublic class XmlPostApp implements CommandLineRunner {\n\n    private final RestTemplate restTemplate = new RestTemplate();\n\n    public static void main(String[] args) {\n        SpringApplication.run(XmlPostApp.class, args);\n    }\n\n    @Override\n    public void run(String... args) {\n\n        String url = \"http:\/\/localhost:8080\/api\/flights\";\n\n        FlightRequest requestBody = new FlightRequest(\"AI-2025\");\n\n        HttpHeaders headers = new HttpHeaders();\n        headers.setContentType(MediaType.APPLICATION_XML);\n\n        HttpEntity request =\n                new HttpEntity(requestBody, headers);\n\n        System.out.println(\"Sending XML POST to: \" + url);\n\n        String response =\n                restTemplate.postForObject(url, request, String.class);\n\n        System.out.println(\"Received Response:\");\n        System.out.println(response);\n    }\n}\n<\/pre>\n<p>In this code, the application defines a <code>CommandLineRunner<\/code> that executes immediately after Spring Boot starts. It constructs a <code>FlightRequest<\/code> object, sets the <code>Content-Type<\/code> to XML, wraps everything inside an <code>HttpEntity<\/code>, and uses <code>RestTemplate<\/code> to send a POST request to the target URL. The console logs both the outgoing request action and the response received from the server, making it easy to verify XML communication during application startup.<\/p>\n<h3>2.5 Code Run and Code Output<\/h3>\n<h4>2.5.1 Code Run<\/h4>\n<p>Once the application is ready, you can run it directly from your IDE or by executing the Spring Boot JAR. Since both the XML client (<code>RestTemplate<\/code>) and the server endpoint are part of the same Spring Boot application, the <code>CommandLineRunner<\/code> will automatically trigger the XML POST request to the local server as soon as the application starts.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">\n# If using Maven\nmvn spring-boot:run\n\n# Or if you packaged the jar\njava -jar xml-post-app-0.0.1-SNAPSHOT.jar\n<\/pre>\n<p>The application will start, initialize the embedded web server on port <code>8080<\/code>, expose the <code>\/api\/flights<\/code> endpoint, and immediately send an XML POST request to that endpoint.<\/p>\n<h4>2.5.2 Code Output<\/h4>\n<h5>2.5.2.1 Client-side Logs<\/h5>\n<pre class=\"brush:plain; wrap-lines:false;\">\n:: Spring Boot ::  (v3.x.x)\n\n2025-01-12T10:15:23  INFO 12345 --- [           main] c.x.XmlPostApp : Starting XmlPostApp\nSending XML POST to: http:\/\/localhost:8080\/api\/flights\nReceived Response:\nFlight request received successfully <\/pre>\n<h5>2.5.2.2 Server-side Logs<\/h5>\n<pre class=\"brush:plain; wrap-lines:false;\">\nReceived XML Request\nFlight Code: AI-2025\n<\/pre>\n<p>The logs confirm that:<\/p>\n<ul>\n<li>The Spring Boot application started successfully.<\/li>\n<li>The <code>CommandLineRunner<\/code> sent an XML POST request using <code>RestTemplate<\/code>.<\/li>\n<li>The local server endpoint received and deserialized the XML payload.<\/li>\n<li>The request contents were logged on the server.<\/li>\n<li>A response was returned to the client.<\/li>\n<\/ul>\n<p>This verifies the complete XML POST lifecycle \u2014 from client serialization to server deserialization \u2014 without requiring any external systems.<\/p>\n<h2><a name=\"section-3\"><\/a>3. Conclusion<\/h2>\n<p>Sending XML in Spring Boot using <code>RestTemplate<\/code> is straightforward when combined with JAXB-based object serialization.  Although <code>WebClient<\/code> is the more modern and reactive alternative, RestTemplate remains an excellent choice for simple, synchronous XML-based legacy API integrations.  With proper configuration and POJO annotations, Spring Boot seamlessly converts Java objects to XML and performs clean and readable HTTP operations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In modern microservice architectures, applications frequently communicate with external systems using REST APIs. While JSON is the most commonly used communication format, many enterprise systems such as banking, aviation, telecom, and legacy SOAP-based services still expect data in XML. Spring Boot provides a convenient way to send XML data using RestTemplate, allowing developers to serialize &hellip;<\/p>\n","protected":false},"author":26931,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[815,30,107],"class_list":["post-139901","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-rest","tag-spring","tag-xml"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Posting XML Data with Spring RestTemplate - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Spring resttemplate xml post requests: A quick guide to Spring RestTemplate XML POST requests with simple code examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Posting XML Data with Spring RestTemplate - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Spring resttemplate xml post requests: A quick guide to Spring RestTemplate XML POST requests with simple code examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2025-12-18T08:15:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin Batra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin Batra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html\"},\"author\":{\"name\":\"Yatin Batra\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\"},\"headline\":\"Posting XML Data with Spring RestTemplate\",\"datePublished\":\"2025-12-18T08:15:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html\"},\"wordCount\":897,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"REST\",\"Spring\",\"XML\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html\",\"name\":\"Posting XML Data with Spring RestTemplate - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2025-12-18T08:15:00+00:00\",\"description\":\"Spring resttemplate xml post requests: A quick guide to Spring RestTemplate XML POST requests with simple code examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/posting-xml-data-with-spring-resttemplate.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Posting XML Data with Spring RestTemplate\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\",\"name\":\"Yatin Batra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"caption\":\"Yatin Batra\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\\\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/yatin-batra\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Posting XML Data with Spring RestTemplate - Java Code Geeks","description":"Spring resttemplate xml post requests: A quick guide to Spring RestTemplate XML POST requests with simple code examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html","og_locale":"en_US","og_type":"article","og_title":"Posting XML Data with Spring RestTemplate - Java Code Geeks","og_description":"Spring resttemplate xml post requests: A quick guide to Spring RestTemplate XML POST requests with simple code examples.","og_url":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2025-12-18T08:15:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Yatin Batra","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin Batra","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html"},"author":{"name":"Yatin Batra","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d"},"headline":"Posting XML Data with Spring RestTemplate","datePublished":"2025-12-18T08:15:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html"},"wordCount":897,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["REST","Spring","XML"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html","url":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html","name":"Posting XML Data with Spring RestTemplate - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2025-12-18T08:15:00+00:00","description":"Spring resttemplate xml post requests: A quick guide to Spring RestTemplate XML POST requests with simple code examples.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/posting-xml-data-with-spring-resttemplate.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Posting XML Data with Spring RestTemplate"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d","name":"Yatin Batra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","caption":"Yatin Batra"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/yatin-batra"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/139901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/26931"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=139901"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/139901\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=139901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=139901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=139901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}