[JAVA] Memorandum (Spring Web)

Qiita's first post. (Also serves as a trial post)

~~ POJO ~~ How to return object type variables in XML format

Originally ~~ POJO ~~ To automatically convert object type variables to Response in json / xml format,

xml.java


@XmlRootElement(name = "test")
@XmlType

I thought that the method on the controller side would automatically return it just by adding the above annotation, but it seems that it is only in JSON format, if you want to make it in XML format,

build.gradle


compile('com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.1')

It seems that it is necessary to add the setting.

The usage of POJO was subtle, so I fixed it.

(Added on 2018/02/16) If you are nesting XML or setting the display method of XML tags in detail, It seems that it is necessary to write a description about JAXB of the site of here. In the return value of each controller (because I wanted to include arbitrary HttpStatus), I wrote something like ResponceEntity <Bean that I want to convert to XML>. Set the return value to ResponceEntity <String>

StringWriter sw = new StringWriter();
JAXB.marshal(BeanToXMLClass,sw);
return ResponceEntity<>(sw.toString(), HttpStatus.OK);

By giving it like You have successfully passed the converted XML string and status code: 200.

Recommended Posts

Memorandum (Spring Web)
Spring Boot Memorandum
[Spring Boot] Web application creation
memorandum
memorandum
Memorandum of understanding when Spring Boot 1.5.10 → Spring Boot 2.0.0
spring × docker
MyBatis memorandum
Java memorandum
About Spring ③
Rails memorandum
Error memorandum
Jaba Jaba Memorandum
Spring Integration Study memorandum ~ Understanding Spring Integration Sample 3. Enricher ~
Start web application development with Spring Boot
JavaFx memorandum
WebMvcConfigurer Memorandum of Understanding for Spring Boot 2.0 (Spring 5)
JAVA memorandum
JUnit memorandum
Spring Java
Gradle Memorandum
Docker memorandum
thymeleaf memorandum
Run WEB application with Spring Boot + Thymeleaf
Spring Integration Study memorandum ~ Understanding Spring Integration Sample 1. Hello World ~
Major changes related to Spring Framework 5.0 Web MVC
Spring Integration Study memorandum ~ Understanding Spring Integration Sample 2. JMS Gateway ~
The official name of Spring MVC is Spring Web MVC
Create a web api server with spring boot
Build a WEB system with Spring + Doma + H2DB