When I'm sending XML payload to REST controller is not mapped as expected. My implementation has been done by using Spring Boot. I have generated the POJOs based on the XSD file using JaxB. XML elements are mapped only if they follow the same naming convention followed in POJO.
<Declaration xmlns:p="My_Common_Types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MY_Schema.xsd">
<ID>ID</ID>
<Regime>REG</Regime>
</Declaration>
Generated Code Using JAXB is as follows,
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "id", "regime" }) @XmlRootElement(name = "Declaration") public class Declaration { @XmlElement(name = "ID") protected String id; @XmlElement(name = "Regime") protected String regime; public String getID() { return id; } public void setID(String value) { this.id = value; } public String getRegime() { return regime; } public void setRegime(String value) { this.regime = value; } }
Rest Controller is as follows,
@RestController public class XMLConsumerController { @PostMapping("/xmlPayload") public void decodeXML(@RequestBody Declaration xmlPayLoad) { } }
pom.xml dependencies are as follows,
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Really appreciate if someone can help me to solve this.