-
Notifications
You must be signed in to change notification settings - Fork 1
feat(SpringBoot4): bump to spring boot 4 and gradle 8.14 #1123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,27 @@ | ||
| package fr.gouv.dgampa.rapportnav.config | ||
|
|
||
| import com.fasterxml.jackson.databind.DeserializationFeature | ||
| import com.fasterxml.jackson.databind.ObjectMapper | ||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies | ||
| import com.fasterxml.jackson.databind.SerializationFeature | ||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule | ||
| import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
| import org.n52.jackson.datatype.jts.JtsModule | ||
| import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer | ||
| import org.springframework.context.annotation.Bean | ||
| import org.springframework.context.annotation.Configuration | ||
| import org.springframework.context.annotation.Primary | ||
| import tools.jackson.databind.DeserializationFeature | ||
| import tools.jackson.databind.PropertyNamingStrategies | ||
| import tools.jackson.databind.cfg.DateTimeFeature | ||
| import tools.jackson.module.kotlin.KotlinModule | ||
|
|
||
| @Configuration | ||
| class JacksonConfig { | ||
|
|
||
| @Bean | ||
| @Primary | ||
| fun objectMapper(): ObjectMapper { | ||
| return ObjectMapper().apply { | ||
| // Register Kotlin module for better Kotlin support | ||
| registerModule(KotlinModule.Builder().build()) | ||
|
|
||
| // Register JavaTimeModule for Java 8 date/time types | ||
| // This handles Instant, ZonedDateTime, LocalDate automatically | ||
| registerModule(JavaTimeModule()) | ||
|
|
||
| // Register JTS module for geometry types | ||
| registerModule(JtsModule()) | ||
|
|
||
| // Configure to serialize dates as ISO-8601 strings (not timestamps) | ||
| disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | ||
|
|
||
| // Don't throw on unrecognised fields | ||
| // Very common for us as we're not always notified by the Monitor apps about changes in their modelds | ||
| disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
| @Bean | ||
| fun jsonMapperBuilderCustomizer(): JsonMapperBuilderCustomizer { | ||
| return JsonMapperBuilderCustomizer { builder -> | ||
| builder.addModule(KotlinModule.Builder().build()) | ||
|
|
||
| // Include null values in serialization (equivalent to gson.serializeNulls()) | ||
| setSerializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include.ALWAYS) | ||
| builder.disable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS) | ||
| builder.disable(DateTimeFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE) | ||
| builder.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
|
|
||
| propertyNamingStrategy = PropertyNamingStrategies.LOWER_CAMEL_CASE | ||
| builder.propertyNamingStrategy(PropertyNamingStrategies.LOWER_CAMEL_CASE) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package fr.gouv.dgampa.rapportnav.config | ||
|
|
||
| import org.locationtech.jts.geom.Geometry | ||
| import org.locationtech.jts.geom.GeometryFactory | ||
| import org.locationtech.jts.geom.MultiPolygon | ||
| import org.locationtech.jts.geom.Polygon | ||
| import org.locationtech.jts.io.ParseException | ||
| import org.locationtech.jts.io.geojson.GeoJsonReader | ||
| import org.locationtech.jts.io.geojson.GeoJsonWriter | ||
| import tools.jackson.core.JsonGenerator | ||
| import tools.jackson.core.JsonParser | ||
| import tools.jackson.core.JsonToken | ||
| import tools.jackson.databind.DeserializationContext | ||
| import tools.jackson.databind.JsonNode | ||
| import tools.jackson.databind.SerializationContext | ||
| import tools.jackson.databind.deser.std.StdDeserializer | ||
| import tools.jackson.databind.ser.std.StdSerializer | ||
| import java.io.IOException | ||
|
|
||
| class JtsGeometryDeserializer( | ||
| private val reader: GeoJsonReader = GeoJsonReader() | ||
| ) : StdDeserializer<Geometry>(Geometry::class.java) { | ||
|
|
||
| override fun deserialize(p: JsonParser, ctxt: DeserializationContext): Geometry { | ||
| val geoJson: String = when (p.currentToken()) { | ||
| JsonToken.VALUE_STRING -> p.text | ||
| else -> (p.readValueAsTree<JsonNode>()).toString() // <-- no codec needed | ||
| } | ||
|
|
||
| try { | ||
| return reader.read(geoJson) | ||
| } catch (e: ParseException) { | ||
| throw IOException("Invalid GeoJSON Geometry", e) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class JtsGeometrySerializer( | ||
| private val writer: GeoJsonWriter = GeoJsonWriter() | ||
| ) : StdSerializer<Geometry>(Geometry::class.java) { | ||
|
|
||
| override fun serialize( | ||
| value: Geometry?, | ||
| gen: JsonGenerator?, | ||
| provider: SerializationContext? | ||
| ) { | ||
| gen?.writeRawValue(writer.write(value)) | ||
| } | ||
| } | ||
|
|
||
| class JtsMultiPolygonDeserializer( | ||
| private val reader: GeoJsonReader = GeoJsonReader(), | ||
| private val gf: GeometryFactory = GeometryFactory() | ||
| ) : StdDeserializer<MultiPolygon>(MultiPolygon::class.java) { | ||
|
|
||
| override fun deserialize(p: JsonParser, ctxt: DeserializationContext): MultiPolygon { | ||
| val geoJson: String = when (p.currentToken()) { | ||
| JsonToken.VALUE_STRING -> p.text | ||
| else -> p.readValueAsTree<JsonNode>().toString() | ||
| } | ||
|
|
||
| val g: Geometry = try { | ||
| reader.read(geoJson) // returns a JTS Geometry | ||
| } catch (e: ParseException) { | ||
| throw IOException("Invalid GeoJSON geometry", e) | ||
| } | ||
|
|
||
| return when (g) { | ||
| is MultiPolygon -> g | ||
| is Polygon -> gf.createMultiPolygon(arrayOf(g)) // promote Polygon -> MultiPolygon | ||
| else -> throw IOException("Expected Polygon or MultiPolygon but got ${g.geometryType}") | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| package fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty | ||
| import com.fasterxml.jackson.annotation.JsonSubTypes | ||
| import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
| import fr.gouv.dgampa.rapportnav.config.JtsGeometryDeserializer | ||
| import fr.gouv.dgampa.rapportnav.config.JtsGeometrySerializer | ||
| import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.ActionCompletionEnum | ||
| import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.tags.TagEntity | ||
| import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.themes.ThemeEntity | ||
| import org.locationtech.jts.geom.Geometry | ||
| import org.n52.jackson.datatype.jts.GeometryDeserializer | ||
| import tools.jackson.databind.annotation.JsonDeserialize | ||
| import tools.jackson.databind.annotation.JsonSerialize | ||
| import java.time.Instant | ||
| import java.util.* | ||
|
|
||
|
|
@@ -32,7 +35,10 @@ abstract class EnvActionEntity( | |
| open val completedBy: String? = null, | ||
| open val completion: ActionCompletionEnum? = null, | ||
| open val controlPlans: List<EnvActionControlPlanEntity>? = listOf(), | ||
| @field:JsonDeserialize(using = GeometryDeserializer::class) open val geom: Geometry? = null, | ||
| @param:JsonProperty("geom") | ||
| @param:JsonDeserialize(using = JtsGeometryDeserializer::class) | ||
| @get:JsonSerialize(using = JtsGeometrySerializer::class) | ||
| open val geom: Geometry? = null, | ||
|
Comment on lines
+38
to
+41
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Faut répéter ça partout pour ce champ maintenant, il faut spécifier quels serializer/deserializer et dans le cas de |
||
| open val isAdministrativeControl: Boolean? = null, | ||
| open val isComplianceWithWaterRegulationsControl: Boolean? = null, | ||
| open val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,24 @@ | ||
| package fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty | ||
| import fr.gouv.dgampa.rapportnav.config.JtsGeometrySerializer | ||
| import fr.gouv.dgampa.rapportnav.config.JtsMultiPolygonDeserializer | ||
| import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.ActionCompletionEnum | ||
| import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.tags.TagEntity | ||
| import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.themes.ThemeEntity | ||
| import org.locationtech.jts.geom.Geometry | ||
| import tools.jackson.databind.annotation.JsonDeserialize | ||
| import tools.jackson.databind.annotation.JsonSerialize | ||
| import java.time.Instant | ||
| import java.util.* | ||
|
|
||
| data class EnvActionSurveillanceEntity( | ||
| override val id: UUID, | ||
| override val actionStartDateTimeUtc: Instant? = null, | ||
| override val actionEndDateTimeUtc: Instant? = null, | ||
| @param:JsonProperty("geom") | ||
| @param:JsonDeserialize(using = JtsMultiPolygonDeserializer::class) | ||
| @get:JsonSerialize(using = JtsGeometrySerializer::class) | ||
|
Comment on lines
+19
to
+21
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mais parfois, c'est des |
||
| override val geom: Geometry? = null, | ||
| override val facade: String? = null, | ||
| override val department: String? = null, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai viré ce code là.
Il suffit de mettre ces propriétés dans
application-propertioes.ymlet ca s'occupe de tout tout seul