1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.geojson.spring.boot.autoconfigure.jackson;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.bremersee.geojson.GeoJsonGeometryFactory;
22 import org.bremersee.geojson.GeoJsonObjectMapperModule;
23 import org.bremersee.geojson.spring.boot.autoconfigure.GeoJsonGeometryFactoryAutoConfiguration;
24 import org.bremersee.geojson.spring.boot.autoconfigure.GeoJsonProperties;
25 import org.springframework.beans.factory.ObjectProvider;
26 import org.springframework.boot.autoconfigure.AutoConfiguration;
27 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
28 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
29 import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
30 import org.springframework.boot.context.event.ApplicationReadyEvent;
31 import org.springframework.boot.context.properties.EnableConfigurationProperties;
32 import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer;
33 import org.springframework.context.event.EventListener;
34 import org.springframework.util.ClassUtils;
35 import tools.jackson.databind.json.JsonMapper.Builder;
36
37
38
39
40
41
42 @ConditionalOnWebApplication
43 @ConditionalOnClass(name = {
44 "org.bremersee.geojson.GeoJsonObjectMapperModule",
45 "tools.jackson.databind.json.JsonMapper"})
46 @AutoConfiguration
47 @AutoConfigureAfter(GeoJsonGeometryFactoryAutoConfiguration.class)
48 @EnableConfigurationProperties(GeoJsonProperties.class)
49 public class GeoJsonJacksonJsonMapperBuilderCustomizer
50 implements JsonMapperBuilderCustomizer {
51
52 private static final Log log = LogFactory
53 .getLog(GeoJsonJacksonJsonMapperBuilderCustomizer.class);
54
55 private final GeoJsonProperties properties;
56
57 private final GeoJsonGeometryFactory geometryFactory;
58
59
60
61
62
63
64
65 public GeoJsonJacksonJsonMapperBuilderCustomizer(
66 GeoJsonProperties properties,
67 ObjectProvider<GeoJsonGeometryFactory> geometryFactory) {
68 this.properties = properties;
69 this.geometryFactory = geometryFactory.getIfAvailable(GeoJsonGeometryFactory::new);
70 }
71
72
73
74
75 @EventListener(ApplicationReadyEvent.class)
76 public void init() {
77 log.info(String.format("""
78
79 *********************************************************************************
80 * %s
81 *********************************************************************************
82 * properties = %s
83 *********************************************************************************""",
84 ClassUtils.getUserClass(getClass()).getSimpleName(), properties));
85 }
86
87 @Override
88 public void customize(Builder jsonMapperBuilder) {
89 GeoJsonObjectMapperModule module = new GeoJsonObjectMapperModule(
90 geometryFactory,
91 properties.isWithBoundingBox(),
92 properties.isUseBigDecimal()
93 );
94 jsonMapperBuilder.addModules(module);
95 }
96 }