47
47
import org .springframework .http .converter .HttpMessageConverter ;
48
48
import org .springframework .http .converter .ResourceHttpMessageConverter ;
49
49
import org .springframework .http .converter .StringHttpMessageConverter ;
50
+ import org .springframework .http .converter .cbor .KotlinSerializationCborHttpMessageConverter ;
50
51
import org .springframework .http .converter .cbor .MappingJackson2CborHttpMessageConverter ;
52
+ import org .springframework .http .converter .feed .AtomFeedHttpMessageConverter ;
53
+ import org .springframework .http .converter .feed .RssChannelHttpMessageConverter ;
51
54
import org .springframework .http .converter .json .GsonHttpMessageConverter ;
52
55
import org .springframework .http .converter .json .JsonbHttpMessageConverter ;
53
56
import org .springframework .http .converter .json .KotlinSerializationJsonHttpMessageConverter ;
54
57
import org .springframework .http .converter .json .MappingJackson2HttpMessageConverter ;
58
+ import org .springframework .http .converter .protobuf .KotlinSerializationProtobufHttpMessageConverter ;
55
59
import org .springframework .http .converter .smile .MappingJackson2SmileHttpMessageConverter ;
56
60
import org .springframework .http .converter .support .AllEncompassingFormHttpMessageConverter ;
61
+ import org .springframework .http .converter .xml .Jaxb2RootElementHttpMessageConverter ;
62
+ import org .springframework .http .converter .xml .MappingJackson2XmlHttpMessageConverter ;
57
63
import org .springframework .http .converter .yaml .MappingJackson2YamlHttpMessageConverter ;
58
64
import org .springframework .util .Assert ;
59
65
import org .springframework .util .ClassUtils ;
@@ -86,20 +92,30 @@ final class DefaultRestClientBuilder implements RestClient.Builder {
86
92
87
93
// message factories
88
94
89
- private static final boolean jackson2Present ;
95
+ private static final boolean romePresent ;
90
96
91
- private static final boolean gsonPresent ;
97
+ private static final boolean jaxb2Present ;
92
98
93
- private static final boolean jsonbPresent ;
99
+ private static final boolean jackson2Present ;
94
100
95
- private static final boolean kotlinSerializationJsonPresent ;
101
+ private static final boolean jackson2XmlPresent ;
96
102
97
103
private static final boolean jackson2SmilePresent ;
98
104
99
105
private static final boolean jackson2CborPresent ;
100
106
101
107
private static final boolean jackson2YamlPresent ;
102
108
109
+ private static final boolean gsonPresent ;
110
+
111
+ private static final boolean jsonbPresent ;
112
+
113
+ private static final boolean kotlinSerializationCborPresent ;
114
+
115
+ private static final boolean kotlinSerializationJsonPresent ;
116
+
117
+ private static final boolean kotlinSerializationProtobufPresent ;
118
+
103
119
104
120
static {
105
121
ClassLoader loader = DefaultRestClientBuilder .class .getClassLoader ();
@@ -109,14 +125,19 @@ final class DefaultRestClientBuilder implements RestClient.Builder {
109
125
reactorNettyClientPresent = ClassUtils .isPresent ("reactor.netty.http.client.HttpClient" , loader );
110
126
jdkClientPresent = ClassUtils .isPresent ("java.net.http.HttpClient" , loader );
111
127
128
+ romePresent = ClassUtils .isPresent ("com.rometools.rome.feed.WireFeed" , loader );
129
+ jaxb2Present = ClassUtils .isPresent ("jakarta.xml.bind.Binder" , loader );
112
130
jackson2Present = ClassUtils .isPresent ("com.fasterxml.jackson.databind.ObjectMapper" , loader ) &&
113
131
ClassUtils .isPresent ("com.fasterxml.jackson.core.JsonGenerator" , loader );
114
- gsonPresent = ClassUtils .isPresent ("com.google.gson.Gson" , loader );
115
- jsonbPresent = ClassUtils .isPresent ("jakarta.json.bind.Jsonb" , loader );
116
- kotlinSerializationJsonPresent = ClassUtils .isPresent ("kotlinx.serialization.json.Json" , loader );
132
+ jackson2XmlPresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.xml.XmlMapper" , loader );
117
133
jackson2SmilePresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.smile.SmileFactory" , loader );
118
134
jackson2CborPresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.cbor.CBORFactory" , loader );
119
135
jackson2YamlPresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.yaml.YAMLFactory" , loader );
136
+ gsonPresent = ClassUtils .isPresent ("com.google.gson.Gson" , loader );
137
+ jsonbPresent = ClassUtils .isPresent ("jakarta.json.bind.Jsonb" , loader );
138
+ kotlinSerializationCborPresent = ClassUtils .isPresent ("kotlinx.serialization.cbor.Cbor" , loader );
139
+ kotlinSerializationJsonPresent = ClassUtils .isPresent ("kotlinx.serialization.json.Json" , loader );
140
+ kotlinSerializationProtobufPresent = ClassUtils .isPresent ("kotlinx.serialization.protobuf.ProtoBuf" , loader );
120
141
}
121
142
122
143
private @ Nullable String baseUrl ;
@@ -419,6 +440,22 @@ private List<HttpMessageConverter<?>> initMessageConverters() {
419
440
this .messageConverters .add (new ResourceHttpMessageConverter (false ));
420
441
this .messageConverters .add (new AllEncompassingFormHttpMessageConverter ());
421
442
443
+ if (romePresent ) {
444
+ this .messageConverters .add (new AtomFeedHttpMessageConverter ());
445
+ this .messageConverters .add (new RssChannelHttpMessageConverter ());
446
+ }
447
+
448
+ if (jackson2XmlPresent ) {
449
+ this .messageConverters .add (new MappingJackson2XmlHttpMessageConverter ());
450
+ }
451
+ else if (jaxb2Present ) {
452
+ this .messageConverters .add (new Jaxb2RootElementHttpMessageConverter ());
453
+ }
454
+
455
+ if (kotlinSerializationProtobufPresent ) {
456
+ this .messageConverters .add (new KotlinSerializationProtobufHttpMessageConverter ());
457
+ }
458
+
422
459
if (jackson2Present ) {
423
460
this .messageConverters .add (new MappingJackson2HttpMessageConverter ());
424
461
}
@@ -437,9 +474,13 @@ else if (kotlinSerializationJsonPresent) {
437
474
if (jackson2CborPresent ) {
438
475
this .messageConverters .add (new MappingJackson2CborHttpMessageConverter ());
439
476
}
477
+ else if (kotlinSerializationCborPresent ) {
478
+ this .messageConverters .add (new KotlinSerializationCborHttpMessageConverter ());
479
+ }
440
480
if (jackson2YamlPresent ) {
441
481
this .messageConverters .add (new MappingJackson2YamlHttpMessageConverter ());
442
482
}
483
+
443
484
}
444
485
return this .messageConverters ;
445
486
}
0 commit comments