From 9637b52f36f286f7b41595315483c1f72547e717 Mon Sep 17 00:00:00 2001 From: Taylor McNeil Date: Wed, 19 Aug 2026 11:58:55 -0400 Subject: [PATCH 1/2] chore: upgrade java and spring. minor update for bean factory to support new spring version. --- mflix/server/java-spring/pom.xml | 8 ++--- .../config/ObjectMapperConfig.java | 30 +++++++++---------- .../src/main/resources/application.properties | 3 ++ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/mflix/server/java-spring/pom.xml b/mflix/server/java-spring/pom.xml index b52cf20..01fea35 100644 --- a/mflix/server/java-spring/pom.xml +++ b/mflix/server/java-spring/pom.xml @@ -8,7 +8,7 @@ org.springframework.boot spring-boot-starter-parent - 4.0.6 + 4.1.0 @@ -20,12 +20,12 @@ 21 - 5.9.0 - 3.0.3 + 5.10.0 + 3.1.0 5.1.0 1.13.0 1.17.8 - 1.15.0-beta25 + 1.19.0-beta29 diff --git a/mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/config/ObjectMapperConfig.java b/mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/config/ObjectMapperConfig.java index 6be474d..1efd6cb 100644 --- a/mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/config/ObjectMapperConfig.java +++ b/mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/config/ObjectMapperConfig.java @@ -1,15 +1,15 @@ package com.mongodb.samplemflix.config; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.bson.types.ObjectId; +import org.springframework.boot.jackson2.autoconfigure.Jackson2ObjectMapperBuilderCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DefaultDataBufferFactory; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; /** * Configuration for customizing the ObjectMapper used for JSON serialization and deserialization. @@ -18,26 +18,24 @@ * custom serializer for MongoDB's ObjectId to convert it to a string representation. * *

It also registers a JavaTimeModule to handle Java 8 date and time types. + * + *

Customizing via {@link Jackson2ObjectMapperBuilderCustomizer} (rather than defining a + * competing {@code ObjectMapper} bean) ensures these settings are applied to the ObjectMapper + * Spring Boot actually uses for HTTP message conversion. */ @Configuration public class ObjectMapperConfig { @Bean - public ObjectMapper objectMapper(JsonFactory jsonFactory) { - ObjectMapper mapper = - new ObjectMapper(jsonFactory) - .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) - .registerModule(new JavaTimeModule()); - SimpleModule module = new SimpleModule(); - module.addSerializer(ObjectId.class, new ObjectIdSerializer()); - mapper.registerModule(module); - return mapper; - } - - @Bean - public JsonFactory jsonFactory() { - return new JsonFactory(); + public Jackson2ObjectMapperBuilderCustomizer objectMapperBuilderCustomizer() { + return (Jackson2ObjectMapperBuilder builder) -> { + builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + builder.modulesToInstall(new JavaTimeModule()); + SimpleModule module = new SimpleModule(); + module.addSerializer(ObjectId.class, new ObjectIdSerializer()); + builder.modulesToInstall(module); + }; } @Bean diff --git a/mflix/server/java-spring/src/main/resources/application.properties b/mflix/server/java-spring/src/main/resources/application.properties index 1e89e1b..d91141e 100644 --- a/mflix/server/java-spring/src/main/resources/application.properties +++ b/mflix/server/java-spring/src/main/resources/application.properties @@ -36,6 +36,9 @@ logging.logback.rollingpolicy.max-file-size=5MB logging.logback.rollingpolicy.max-history=5 # Jackson Configuration (JSON serialization) +# This app uses Jackson 2 (custom ObjectId serializer, spring.jackson2.* config below); +# Spring Boot 4.1 defaults HTTP message conversion to Jackson 3 unless pinned here. +spring.http.converters.preferred-json-mapper=jackson2 spring.jackson2.default-property-inclusion=non_null # API Documentation (Swagger/OpenAPI) From e745a4f60d392e5e7f9d14eaaf2e5dcf84c9d547 Mon Sep 17 00:00:00 2001 From: Taylor McNeil Date: Wed, 19 Aug 2026 12:04:49 -0400 Subject: [PATCH 2/2] removing note --- .../com/mongodb/samplemflix/config/ObjectMapperConfig.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/config/ObjectMapperConfig.java b/mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/config/ObjectMapperConfig.java index 1efd6cb..7366c88 100644 --- a/mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/config/ObjectMapperConfig.java +++ b/mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/config/ObjectMapperConfig.java @@ -19,9 +19,6 @@ * *

It also registers a JavaTimeModule to handle Java 8 date and time types. * - *

Customizing via {@link Jackson2ObjectMapperBuilderCustomizer} (rather than defining a - * competing {@code ObjectMapper} bean) ensures these settings are applied to the ObjectMapper - * Spring Boot actually uses for HTTP message conversion. */ @Configuration