SpringRESTXML
SpringRESTXML
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
B. Bootstrapping of application
Example: GfgRestXmlResponseApplication.java
Java
@SpringBootApplication
public class GfgRestXmlResponseApplication {
public static void main(String[] args)
{ SpringApplication.run(
GfgRestXmlResponseApplication.class, args);
}
}
// Annotations
@RestController
@RequestMapping(path = "/xml-output",
produces = "application/xml")
// Class
public class RestXMLResponseController {
@GetMapping("/get")
public ResponseEntity<EntityModel> get()
{
return entityModel;
}
// Annotation
@GetMapping("/get/{id}")
// Class
public ResponseEntity<EntityModel>
getById(@PathVariable("id") String id)
{
return entityModel;
}
}
Output 1:
Output 2:
// Class
public class ConsumeXMLResponse {
return
rest.getForEntity("http://localhost:8080/xml-output/get/{id}",
EntityModel.class, id);
}
}