Skip to content

Commit 221ff8d

Browse files
larsgrefersnicoll
authored andcommitted
Update instructions on how to use JAXB as XML renderer
See gh-16005
1 parent 5332669 commit 221ff8d

File tree

1 file changed

+19
-6
lines changed
  • spring-boot-project/spring-boot-docs/src/main/asciidoc

1 file changed

+19
-6
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,15 @@ tend to send accept headers that prefer XML.
11541154

11551155
[[howto-write-an-xml-rest-service]]
11561156
=== Write an XML REST Service
1157-
If you have the Jackson XML extension (`jackson-dataformat-xml`) on the classpath, you
1157+
If you have the Jackson XML extension (`jackson-dataformat-xml`) or JAXB on the classpath, you
11581158
can use it to render XML responses. The previous example that we used for JSON would
1159-
work. To use the Jackson XML renderer, add the following dependency to your project:
1159+
work.
1160+
1161+
NOTE: To get the server to render XML instead of JSON, you might have to send an
1162+
`Accept: text/xml` header (or use a browser).
1163+
1164+
==== Jackson XML
1165+
To use the Jackson XML renderer, add the following dependency to your project:
11601166

11611167
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
11621168
----
@@ -1166,8 +1172,9 @@ work. To use the Jackson XML renderer, add the following dependency to your proj
11661172
</dependency>
11671173
----
11681174

1169-
If Jackson's XML extension is not available, JAXB (provided by default in the JDK) is
1170-
used, with the additional requirement of having `MyThing` annotated as
1175+
==== JAXB
1176+
If Jackson's XML extension is not available, JAXB is tried next,
1177+
with the additional requirement of having `MyThing` annotated as
11711178
`@XmlRootElement`, as shown in the following example:
11721179

11731180
[source,java,indent=0,subs="verbatim,quotes,attributes"]
@@ -1179,9 +1186,15 @@ used, with the additional requirement of having `MyThing` annotated as
11791186
}
11801187
----
11811188

1182-
To get the server to render XML instead of JSON, you might have to send an
1183-
`Accept: text/xml` header (or use a browser).
1189+
To use JAXB as XML renderer, add the following dependency to your project:
11841190

1191+
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
1192+
----
1193+
<dependency>
1194+
<groupId>org.glassfish.jaxb</groupId>
1195+
<artifactId>jaxb-runtime</artifactId>
1196+
</dependency>
1197+
----
11851198

11861199

11871200
[[howto-customize-the-jackson-objectmapper]]

0 commit comments

Comments
 (0)