Last active
January 28, 2024 21:31
-
-
Save aoudiamoncef/820981bb850b7f432899ccf2ebfa503a to your computer and use it in GitHub Desktop.
Spring Boot specify Jackson module(s) to register with the ObjectMapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>3.2.2</version> | |
<relativePath/> <!-- lookup parent from repository --> | |
</parent> | |
<groupId>com.maoudia.app</groupId> | |
<artifactId>app</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<name>maoudia-app</name> | |
<description>MAOUDIA APP</description> | |
<properties> | |
<java.version>21</java.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-web</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>com.fasterxml.jackson.module</groupId> | |
<artifactId>jackson-module-blackbird</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>com.fasterxml.jackson.datatype</groupId> | |
<artifactId>jackson-datatype-hibernate6</artifactId> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-maven-plugin</artifactId> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.maoudia; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.fasterxml.jackson.databind.SerializationFeature; | |
import com.fasterxml.jackson.datatype.hibernate6.Hibernate6Module; | |
import com.fasterxml.jackson.module.blackbird.BlackbirdModule; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | |
@Configuration | |
public class SerdeConfig { | |
@Bean | |
public ObjectMapper jacksonObjectMapper() { | |
return Jackson2ObjectMapperBuilder.json() | |
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | |
.modulesToInstall(new BlackbirdModule(), new Hibernate6Module()) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment