1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.http.converter.support;
18
19 import javax.xml.transform.Source;
20
21 import org.springframework.http.converter.FormHttpMessageConverter;
22 import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
23 import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter;
24 import org.springframework.http.converter.xml.SourceHttpMessageConverter;
25 import org.springframework.util.ClassUtils;
26
27
28
29
30
31
32
33
34 public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConverter {
35
36 private static final boolean jaxb2Present =
37 ClassUtils.isPresent("javax.xml.bind.Binder", AllEncompassingFormHttpMessageConverter.class.getClassLoader());
38
39 private static final boolean jackson2Present =
40 ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", AllEncompassingFormHttpMessageConverter.class.getClassLoader()) &&
41 ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", AllEncompassingFormHttpMessageConverter.class.getClassLoader());
42
43
44 public AllEncompassingFormHttpMessageConverter() {
45 addPartConverter(new SourceHttpMessageConverter<Source>());
46 if (jaxb2Present) {
47 addPartConverter(new Jaxb2RootElementHttpMessageConverter());
48 }
49 if (jackson2Present) {
50 addPartConverter(new MappingJackson2HttpMessageConverter());
51 }
52 }
53
54 }