1
1
/*
2
- * Copyright 2002-2024 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
44
44
import org .springframework .http .converter .HttpMessageConverter ;
45
45
import org .springframework .http .converter .ResourceHttpMessageConverter ;
46
46
import org .springframework .http .converter .StringHttpMessageConverter ;
47
+ import org .springframework .http .converter .cbor .KotlinSerializationCborHttpMessageConverter ;
47
48
import org .springframework .http .converter .cbor .MappingJackson2CborHttpMessageConverter ;
49
+ import org .springframework .http .converter .feed .AtomFeedHttpMessageConverter ;
50
+ import org .springframework .http .converter .feed .RssChannelHttpMessageConverter ;
48
51
import org .springframework .http .converter .json .GsonHttpMessageConverter ;
49
52
import org .springframework .http .converter .json .JsonbHttpMessageConverter ;
50
53
import org .springframework .http .converter .json .KotlinSerializationJsonHttpMessageConverter ;
51
54
import org .springframework .http .converter .json .MappingJackson2HttpMessageConverter ;
55
+ import org .springframework .http .converter .protobuf .KotlinSerializationProtobufHttpMessageConverter ;
52
56
import org .springframework .http .converter .smile .MappingJackson2SmileHttpMessageConverter ;
53
57
import org .springframework .http .converter .support .AllEncompassingFormHttpMessageConverter ;
58
+ import org .springframework .http .converter .xml .Jaxb2RootElementHttpMessageConverter ;
59
+ import org .springframework .http .converter .xml .MappingJackson2XmlHttpMessageConverter ;
54
60
import org .springframework .http .converter .yaml .MappingJackson2YamlHttpMessageConverter ;
55
61
import org .springframework .lang .Nullable ;
56
62
import org .springframework .util .Assert ;
@@ -84,20 +90,30 @@ final class DefaultRestClientBuilder implements RestClient.Builder {
84
90
85
91
// message factories
86
92
87
- private static final boolean jackson2Present ;
93
+ private static final boolean romePresent ;
88
94
89
- private static final boolean gsonPresent ;
95
+ private static final boolean jaxb2Present ;
90
96
91
- private static final boolean jsonbPresent ;
97
+ private static final boolean jackson2Present ;
92
98
93
- private static final boolean kotlinSerializationJsonPresent ;
99
+ private static final boolean jackson2XmlPresent ;
94
100
95
101
private static final boolean jackson2SmilePresent ;
96
102
97
103
private static final boolean jackson2CborPresent ;
98
104
99
105
private static final boolean jackson2YamlPresent ;
100
106
107
+ private static final boolean gsonPresent ;
108
+
109
+ private static final boolean jsonbPresent ;
110
+
111
+ private static final boolean kotlinSerializationCborPresent ;
112
+
113
+ private static final boolean kotlinSerializationJsonPresent ;
114
+
115
+ private static final boolean kotlinSerializationProtobufPresent ;
116
+
101
117
102
118
static {
103
119
ClassLoader loader = DefaultRestClientBuilder .class .getClassLoader ();
@@ -107,14 +123,19 @@ final class DefaultRestClientBuilder implements RestClient.Builder {
107
123
reactorNettyClientPresent = ClassUtils .isPresent ("reactor.netty.http.client.HttpClient" , loader );
108
124
jdkClientPresent = ClassUtils .isPresent ("java.net.http.HttpClient" , loader );
109
125
126
+ romePresent = ClassUtils .isPresent ("com.rometools.rome.feed.WireFeed" , loader );
127
+ jaxb2Present = ClassUtils .isPresent ("jakarta.xml.bind.Binder" , loader );
110
128
jackson2Present = ClassUtils .isPresent ("com.fasterxml.jackson.databind.ObjectMapper" , loader ) &&
111
129
ClassUtils .isPresent ("com.fasterxml.jackson.core.JsonGenerator" , loader );
112
- gsonPresent = ClassUtils .isPresent ("com.google.gson.Gson" , loader );
113
- jsonbPresent = ClassUtils .isPresent ("jakarta.json.bind.Jsonb" , loader );
114
- kotlinSerializationJsonPresent = ClassUtils .isPresent ("kotlinx.serialization.json.Json" , loader );
130
+ jackson2XmlPresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.xml.XmlMapper" , loader );
115
131
jackson2SmilePresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.smile.SmileFactory" , loader );
116
132
jackson2CborPresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.cbor.CBORFactory" , loader );
117
133
jackson2YamlPresent = ClassUtils .isPresent ("com.fasterxml.jackson.dataformat.yaml.YAMLFactory" , loader );
134
+ gsonPresent = ClassUtils .isPresent ("com.google.gson.Gson" , loader );
135
+ jsonbPresent = ClassUtils .isPresent ("jakarta.json.bind.Jsonb" , loader );
136
+ kotlinSerializationCborPresent = ClassUtils .isPresent ("kotlinx.serialization.cbor.Cbor" , loader );
137
+ kotlinSerializationJsonPresent = ClassUtils .isPresent ("kotlinx.serialization.json.Json" , loader );
138
+ kotlinSerializationProtobufPresent = ClassUtils .isPresent ("kotlinx.serialization.protobuf.ProtoBuf" , loader );
118
139
}
119
140
120
141
@ Nullable
@@ -428,6 +449,22 @@ private List<HttpMessageConverter<?>> initMessageConverters() {
428
449
this .messageConverters .add (new ResourceHttpMessageConverter (false ));
429
450
this .messageConverters .add (new AllEncompassingFormHttpMessageConverter ());
430
451
452
+ if (romePresent ) {
453
+ this .messageConverters .add (new AtomFeedHttpMessageConverter ());
454
+ this .messageConverters .add (new RssChannelHttpMessageConverter ());
455
+ }
456
+
457
+ if (jackson2XmlPresent ) {
458
+ this .messageConverters .add (new MappingJackson2XmlHttpMessageConverter ());
459
+ }
460
+ else if (jaxb2Present ) {
461
+ this .messageConverters .add (new Jaxb2RootElementHttpMessageConverter ());
462
+ }
463
+
464
+ if (kotlinSerializationProtobufPresent ) {
465
+ this .messageConverters .add (new KotlinSerializationProtobufHttpMessageConverter ());
466
+ }
467
+
431
468
if (kotlinSerializationJsonPresent ) {
432
469
this .messageConverters .add (new KotlinSerializationJsonHttpMessageConverter ());
433
470
}
@@ -446,9 +483,13 @@ else if (jsonbPresent) {
446
483
if (jackson2CborPresent ) {
447
484
this .messageConverters .add (new MappingJackson2CborHttpMessageConverter ());
448
485
}
486
+ else if (kotlinSerializationCborPresent ) {
487
+ this .messageConverters .add (new KotlinSerializationCborHttpMessageConverter ());
488
+ }
449
489
if (jackson2YamlPresent ) {
450
490
this .messageConverters .add (new MappingJackson2YamlHttpMessageConverter ());
451
491
}
492
+
452
493
}
453
494
return this .messageConverters ;
454
495
}
0 commit comments