From f7adc9da0f0093688489cf4ca83a129ee3d2d7c1 Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Wed, 20 Feb 2019 14:38:30 +0100 Subject: [PATCH 1/2] JAXB is only present in JDK 8 --- .../spring-boot-docs/src/main/asciidoc/howto.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc index a9422a83ad6a..225590b60cb9 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1167,7 +1167,7 @@ work. To use the Jackson XML renderer, add the following dependency to your proj ---- -If Jackson's XML extension is not available, JAXB (provided by default in the JDK) is +If Jackson's XML extension is not available, JAXB (provided by default in the JDK 8) is used, with the additional requirement of having `MyThing` annotated as `@XmlRootElement`, as shown in the following example: From 41571280624c95be8bf42c5a24e06789bfcd950b Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Sat, 23 Feb 2019 17:12:16 +0100 Subject: [PATCH 2/2] Update howto.adoc Update instructions on how to use JAXB as XML renderer. --- .../src/main/asciidoc/howto.adoc | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc index 225590b60cb9..e86d43812f11 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1155,9 +1155,15 @@ tend to send accept headers that prefer XML. [[howto-write-an-xml-rest-service]] === Write an XML REST Service -If you have the Jackson XML extension (`jackson-dataformat-xml`) on the classpath, you +If you have the Jackson XML extension (`jackson-dataformat-xml`) or JAXB on the classpath, you can use it to render XML responses. The previous example that we used for JSON would -work. To use the Jackson XML renderer, add the following dependency to your project: +work. + +NOTE: To get the server to render XML instead of JSON, you might have to send an +`Accept: text/xml` header (or use a browser). + +==== Jackson XML +To use the Jackson XML renderer, add the following dependency to your project: [source,xml,indent=0,subs="verbatim,quotes,attributes"] ---- @@ -1167,8 +1173,9 @@ work. To use the Jackson XML renderer, add the following dependency to your proj ---- -If Jackson's XML extension is not available, JAXB (provided by default in the JDK 8) is -used, with the additional requirement of having `MyThing` annotated as +==== JAXB +If Jackson's XML extension is not available, JAXB is tried next, +with the additional requirement of having `MyThing` annotated as `@XmlRootElement`, as shown in the following example: [source,java,indent=0,subs="verbatim,quotes,attributes"] @@ -1180,9 +1187,15 @@ used, with the additional requirement of having `MyThing` annotated as } ---- -To get the server to render XML instead of JSON, you might have to send an -`Accept: text/xml` header (or use a browser). +To use JAXB as XML renderer, add the following dependency to your project: +[source,xml,indent=0,subs="verbatim,quotes,attributes"] +---- + + org.glassfish.jaxb + jaxb-runtime + +---- [[howto-customize-the-jackson-objectmapper]]