17
17
package org .springframework .http .converter .support ;
18
18
19
19
import org .springframework .http .converter .FormHttpMessageConverter ;
20
+ import org .springframework .http .converter .cbor .JacksonCborHttpMessageConverter ;
20
21
import org .springframework .http .converter .cbor .KotlinSerializationCborHttpMessageConverter ;
21
22
import org .springframework .http .converter .cbor .MappingJackson2CborHttpMessageConverter ;
22
23
import org .springframework .http .converter .json .GsonHttpMessageConverter ;
24
+ import org .springframework .http .converter .json .JacksonJsonHttpMessageConverter ;
23
25
import org .springframework .http .converter .json .JsonbHttpMessageConverter ;
24
26
import org .springframework .http .converter .json .KotlinSerializationJsonHttpMessageConverter ;
25
27
import org .springframework .http .converter .json .MappingJackson2HttpMessageConverter ;
26
28
import org .springframework .http .converter .protobuf .KotlinSerializationProtobufHttpMessageConverter ;
29
+ import org .springframework .http .converter .smile .JacksonSmileHttpMessageConverter ;
27
30
import org .springframework .http .converter .smile .MappingJackson2SmileHttpMessageConverter ;
31
+ import org .springframework .http .converter .xml .JacksonXmlHttpMessageConverter ;
28
32
import org .springframework .http .converter .xml .Jaxb2RootElementHttpMessageConverter ;
29
33
import org .springframework .http .converter .xml .MappingJackson2XmlHttpMessageConverter ;
34
+ import org .springframework .http .converter .yaml .JacksonYamlHttpMessageConverter ;
30
35
import org .springframework .http .converter .yaml .MappingJackson2YamlHttpMessageConverter ;
31
36
import org .springframework .util .ClassUtils ;
32
37
@@ -44,14 +49,24 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
44
49
45
50
private static final boolean jaxb2Present ;
46
51
52
+ private static final boolean jacksonPresent ;
53
+
47
54
private static final boolean jackson2Present ;
48
55
56
+ private static final boolean jacksonXmlPresent ;
57
+
49
58
private static final boolean jackson2XmlPresent ;
50
59
60
+ private static final boolean jacksonSmilePresent ;
61
+
51
62
private static final boolean jackson2SmilePresent ;
52
63
64
+ private static final boolean jacksonCborPresent ;
65
+
53
66
private static final boolean jackson2CborPresent ;
54
67
68
+ private static final boolean jacksonYamlPresent ;
69
+
55
70
private static final boolean jackson2YamlPresent ;
56
71
57
72
private static final boolean gsonPresent ;
@@ -67,12 +82,17 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
67
82
static {
68
83
ClassLoader classLoader = AllEncompassingFormHttpMessageConverter .class .getClassLoader ();
69
84
jaxb2Present = ClassUtils .isPresent ("jakarta.xml.bind.Binder" , classLoader );
85
+ jacksonPresent = ClassUtils .isPresent ("tools.jackson.databind.ObjectMapper" , classLoader );
70
86
jackson2Present = ClassUtils .isPresent ("com.fasterxml.jackson.databind.ObjectMapper" , classLoader ) &&
71
87
ClassUtils .isPresent ("com.fasterxml.jackson.core.JsonGenerator" , classLoader );
72
- jackson2XmlPresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.xml.XmlMapper" , classLoader );
73
- jackson2SmilePresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.smile.SmileFactory" , classLoader );
74
- jackson2CborPresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.cbor.CBORFactory" , classLoader );
75
- jackson2YamlPresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.yaml.YAMLFactory" , classLoader );
88
+ jacksonXmlPresent = jacksonPresent && ClassUtils .isPresent ("tools.jackson.dataformat.xml.XmlMapper" , classLoader );
89
+ jackson2XmlPresent = jackson2Present && ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.xml.XmlMapper" , classLoader );
90
+ jacksonSmilePresent = jacksonPresent && ClassUtils .isPresent ("tools.jackson.dataformat.smile.SmileMapper" , classLoader );
91
+ jackson2SmilePresent = jackson2Present && ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.smile.SmileFactory" , classLoader );
92
+ jacksonCborPresent = jacksonPresent && ClassUtils .isPresent ("tools.jackson.dataformat.cbor.CBORMapper" , classLoader );
93
+ jackson2CborPresent = jackson2Present && ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.cbor.CBORFactory" , classLoader );
94
+ jacksonYamlPresent = jacksonPresent && ClassUtils .isPresent ("tools.jackson.dataformat.yaml.YAMLMapper" , classLoader );
95
+ jackson2YamlPresent = jackson2Present && ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.yaml.YAMLFactory" , classLoader );
76
96
gsonPresent = ClassUtils .isPresent ("com.google.gson.Gson" , classLoader );
77
97
jsonbPresent = ClassUtils .isPresent ("jakarta.json.bind.Jsonb" , classLoader );
78
98
kotlinSerializationCborPresent = ClassUtils .isPresent ("kotlinx.serialization.cbor.Cbor" , classLoader );
@@ -83,11 +103,14 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
83
103
84
104
public AllEncompassingFormHttpMessageConverter () {
85
105
86
- if (jaxb2Present && !jackson2XmlPresent ) {
106
+ if (jaxb2Present && !jacksonXmlPresent && ! jackson2XmlPresent ) {
87
107
addPartConverter (new Jaxb2RootElementHttpMessageConverter ());
88
108
}
89
109
90
- if (jackson2Present ) {
110
+ if (jacksonPresent ) {
111
+ addPartConverter (new JacksonJsonHttpMessageConverter ());
112
+ }
113
+ else if (jackson2Present ) {
91
114
addPartConverter (new MappingJackson2HttpMessageConverter ());
92
115
}
93
116
else if (gsonPresent ) {
@@ -100,22 +123,34 @@ else if (kotlinSerializationJsonPresent) {
100
123
addPartConverter (new KotlinSerializationJsonHttpMessageConverter ());
101
124
}
102
125
103
- if (jackson2XmlPresent ) {
126
+ if (jacksonXmlPresent ) {
127
+ addPartConverter (new JacksonXmlHttpMessageConverter ());
128
+ }
129
+ else if (jackson2XmlPresent ) {
104
130
addPartConverter (new MappingJackson2XmlHttpMessageConverter ());
105
131
}
106
132
107
- if (jackson2SmilePresent ) {
133
+ if (jacksonSmilePresent ) {
134
+ addPartConverter (new JacksonSmileHttpMessageConverter ());
135
+ }
136
+ else if (jackson2SmilePresent ) {
108
137
addPartConverter (new MappingJackson2SmileHttpMessageConverter ());
109
138
}
110
139
111
- if (jackson2CborPresent ) {
140
+ if (jacksonCborPresent ) {
141
+ addPartConverter (new JacksonCborHttpMessageConverter ());
142
+ }
143
+ else if (jackson2CborPresent ) {
112
144
addPartConverter (new MappingJackson2CborHttpMessageConverter ());
113
145
}
114
146
else if (kotlinSerializationCborPresent ) {
115
147
addPartConverter (new KotlinSerializationCborHttpMessageConverter ());
116
148
}
117
149
118
- if (jackson2YamlPresent ) {
150
+ if (jacksonYamlPresent ) {
151
+ addPartConverter (new JacksonYamlHttpMessageConverter ());
152
+ }
153
+ else if (jackson2YamlPresent ) {
119
154
addPartConverter (new MappingJackson2YamlHttpMessageConverter ());
120
155
}
121
156
0 commit comments