From 221ff8d69fe73ee3dafe2d8a97360fc67f7dc697 Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Wed, 20 Feb 2019 14:38:30 +0100 Subject: [PATCH 1/2] Update instructions on how to use JAXB as XML renderer See gh-16005 --- .../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 1a18d5450c1..ec5f99e046b 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 @@ -1154,9 +1154,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"] ---- @@ -1166,8 +1172,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) 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"] @@ -1179,9 +1186,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]] From c47edd15af2ea3264f548f6ad1c972246e9367f8 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 26 Feb 2019 16:57:47 +0100 Subject: [PATCH 2/2] Polish "Update instructions on how to use JAXB as XML renderer" Closes gh-16005 --- .../src/main/asciidoc/howto.adoc | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 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 ec5f99e046b..d52e645b90e 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 @@ -1154,15 +1154,9 @@ 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`) or JAXB on the classpath, you +If you have the Jackson XML extension (`jackson-dataformat-xml`) on the classpath, you can use it to render XML responses. The previous example that we used for JSON would -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: +work. To use the Jackson XML renderer, add the following dependency to your project: [source,xml,indent=0,subs="verbatim,quotes,attributes"] ---- @@ -1172,10 +1166,9 @@ To use the Jackson XML renderer, add the following dependency to your project: ---- -==== 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: +If Jackson's XML extension is not available and JAXB is available, XML can be rendered +with the additional requirement of having `MyThing` annotated as `@XmlRootElement`, as +shown in the following example: [source,java,indent=0,subs="verbatim,quotes,attributes"] ---- @@ -1186,7 +1179,8 @@ with the additional requirement of having `MyThing` annotated as } ---- -To use JAXB as XML renderer, add the following dependency to your project: +JAXB is only available out of the box with Java 8. If you're using a more recent java +generation, add the following dependency to your project: [source,xml,indent=0,subs="verbatim,quotes,attributes"] ---- @@ -1196,6 +1190,10 @@ To use JAXB as XML renderer, add the following dependency to your project: ---- +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). + + [[howto-customize-the-jackson-objectmapper]] === Customize the Jackson ObjectMapper