Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mflix/server/java-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.0.6</version>
<version>4.1.0</version>
<relativePath/>
</parent>

Expand All @@ -20,12 +20,12 @@

<properties>
<java.version>21</java.version>
<mongodb.version>5.9.0</mongodb.version>
<springdoc.version>3.0.3</springdoc.version>
<mongodb.version>5.10.0</mongodb.version>
<springdoc.version>3.1.0</springdoc.version>
<dotenv.version>5.1.0</dotenv.version>
<impsort.plugin.version>1.13.0</impsort.plugin.version>
<byte-buddy.version>1.17.8</byte-buddy.version>
<langchain4j.version>1.15.0-beta25</langchain4j.version>
<langchain4j.version>1.19.0-beta29</langchain4j.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,26 +18,21 @@
* custom serializer for MongoDB's ObjectId to convert it to a string representation.
*
* <p>It also registers a JavaTimeModule to handle Java 8 date and time types.
*
*/

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down