|
40 | 40 | import tools.jackson.databind.cfg.MapperBuilder; |
41 | 41 | import tools.jackson.databind.json.JsonMapper; |
42 | 42 | import tools.jackson.dataformat.cbor.CBORMapper; |
| 43 | +import tools.jackson.dataformat.xml.XmlMapper; |
43 | 44 |
|
44 | 45 | import org.springframework.aot.hint.ReflectionHints; |
45 | 46 | import org.springframework.aot.hint.RuntimeHints; |
@@ -163,7 +164,7 @@ public void customize(JsonMapper.Builder builder) { |
163 | 164 |
|
164 | 165 | @Configuration(proxyBeanMethods = false) |
165 | 166 | @ConditionalOnClass(ProblemDetail.class) |
166 | | - static class ProblemDetailsConfiguration { |
| 167 | + static class JsonProblemDetailsConfiguration { |
167 | 168 |
|
168 | 169 | @Bean |
169 | 170 | ProblemDetailJsonMapperBuilderCustomizer problemDetailJsonMapperBuilderCustomizer() { |
@@ -236,6 +237,80 @@ public void customize(CBORMapper.Builder builder) { |
236 | 237 |
|
237 | 238 | } |
238 | 239 |
|
| 240 | + @Configuration(proxyBeanMethods = false) |
| 241 | + @ConditionalOnClass(XmlMapper.class) |
| 242 | + @EnableConfigurationProperties(JacksonXmlProperties.class) |
| 243 | + static class XmlConfiguration { |
| 244 | + |
| 245 | + @Bean |
| 246 | + @ConditionalOnMissingBean |
| 247 | + XmlMapper xmlMapper(XmlMapper.Builder builder) { |
| 248 | + return builder.build(); |
| 249 | + } |
| 250 | + |
| 251 | + @Bean |
| 252 | + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) |
| 253 | + @ConditionalOnMissingBean |
| 254 | + XmlMapper.Builder xmlMapperBuilder(List<XmlMapperBuilderCustomizer> customizers) { |
| 255 | + XmlMapper.Builder builder = XmlMapper.builder(); |
| 256 | + customize(builder, customizers); |
| 257 | + return builder; |
| 258 | + } |
| 259 | + |
| 260 | + private void customize(XmlMapper.Builder builder, List<XmlMapperBuilderCustomizer> customizers) { |
| 261 | + for (XmlMapperBuilderCustomizer customizer : customizers) { |
| 262 | + customizer.customize(builder); |
| 263 | + } |
| 264 | + } |
| 265 | + |
| 266 | + @Bean |
| 267 | + StandardXmlMapperBuilderCustomizer standardXmlMapperBuilderCustomizer(JacksonProperties jacksonProperties, |
| 268 | + ObjectProvider<JacksonModule> modules, JacksonXmlProperties xmlProperties) { |
| 269 | + return new StandardXmlMapperBuilderCustomizer(jacksonProperties, modules.stream().toList(), xmlProperties); |
| 270 | + } |
| 271 | + |
| 272 | + @Configuration(proxyBeanMethods = false) |
| 273 | + @ConditionalOnClass(ProblemDetail.class) |
| 274 | + static class XmlProblemDetailsConfiguration { |
| 275 | + |
| 276 | + @Bean |
| 277 | + ProblemDetailXmlMapperBuilderCustomizer problemDetailXmlMapperBuilderCustomizer() { |
| 278 | + return new ProblemDetailXmlMapperBuilderCustomizer(); |
| 279 | + } |
| 280 | + |
| 281 | + static final class ProblemDetailXmlMapperBuilderCustomizer implements XmlMapperBuilderCustomizer { |
| 282 | + |
| 283 | + @Override |
| 284 | + public void customize(XmlMapper.Builder builder) { |
| 285 | + builder.addMixIn(ProblemDetail.class, ProblemDetailJacksonMixin.class); |
| 286 | + } |
| 287 | + |
| 288 | + } |
| 289 | + |
| 290 | + } |
| 291 | + |
| 292 | + static class StandardXmlMapperBuilderCustomizer extends AbstractMapperBuilderCustomizer<XmlMapper.Builder> |
| 293 | + implements XmlMapperBuilderCustomizer { |
| 294 | + |
| 295 | + private final JacksonXmlProperties xmlProperties; |
| 296 | + |
| 297 | + StandardXmlMapperBuilderCustomizer(JacksonProperties jacksonProperties, Collection<JacksonModule> modules, |
| 298 | + JacksonXmlProperties xmlProperties) { |
| 299 | + super(jacksonProperties, modules); |
| 300 | + this.xmlProperties = xmlProperties; |
| 301 | + } |
| 302 | + |
| 303 | + @Override |
| 304 | + public void customize(XmlMapper.Builder builder) { |
| 305 | + super.customize(builder); |
| 306 | + configureFeatures(builder, this.xmlProperties.getRead(), builder::configure); |
| 307 | + configureFeatures(builder, this.xmlProperties.getWrite(), builder::configure); |
| 308 | + } |
| 309 | + |
| 310 | + } |
| 311 | + |
| 312 | + } |
| 313 | + |
239 | 314 | static class JacksonAutoConfigurationRuntimeHints implements RuntimeHintsRegistrar { |
240 | 315 |
|
241 | 316 | @Override |
|
0 commit comments