47
47
import org .springframework .http .converter .json .MappingJackson2HttpMessageConverter ;
48
48
import org .springframework .http .converter .support .AllEncompassingFormHttpMessageConverter ;
49
49
import org .springframework .http .converter .xml .Jaxb2RootElementHttpMessageConverter ;
50
+ import org .springframework .http .converter .xml .MappingJackson2XmlHttpMessageConverter ;
50
51
import org .springframework .http .converter .xml .SourceHttpMessageConverter ;
51
52
import org .springframework .util .Assert ;
52
53
import org .springframework .util .ClassUtils ;
@@ -122,6 +123,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
122
123
ClassUtils .isPresent ("com.fasterxml.jackson.databind.ObjectMapper" , RestTemplate .class .getClassLoader ()) &&
123
124
ClassUtils .isPresent ("com.fasterxml.jackson.core.JsonGenerator" , RestTemplate .class .getClassLoader ());
124
125
126
+ private static final boolean jackson2XmlPresent =
127
+ ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.xml.XmlMapper" , RestTemplate .class .getClassLoader ());
128
+
125
129
private static final boolean gsonPresent =
126
130
ClassUtils .isPresent ("com.google.gson.Gson" , RestTemplate .class .getClassLoader ());
127
131
@@ -148,7 +152,10 @@ public RestTemplate() {
148
152
this .messageConverters .add (new AtomFeedHttpMessageConverter ());
149
153
this .messageConverters .add (new RssChannelHttpMessageConverter ());
150
154
}
151
- if (jaxb2Present ) {
155
+ if (jackson2XmlPresent ) {
156
+ messageConverters .add (new MappingJackson2XmlHttpMessageConverter ());
157
+ }
158
+ else if (jaxb2Present ) {
152
159
this .messageConverters .add (new Jaxb2RootElementHttpMessageConverter ());
153
160
}
154
161
if (jackson2Present ) {
0 commit comments