---
title: "How to configure custom Redis serialization in Spring Boot?"  
description: "How to configure custom Redis serialization in Spring Boot?"  
author: "Lily Chitlangiya"  
published: 2026-09-17  
canonical: https://answers.mindstick.com/qa/117201/how-to-configure-custom-redis-serialization-in-spring-boot  
category: "Spring Boot"  
tags: ["Spring Boot", "java", "Redis", "Serialization"]  
reading_time: 1 minute  

---

# How to configure custom Redis serialization in Spring Boot?

By default, **Spring Data Redis** uses standard Java JDK serialization, which outputs unreadable binary strings into Redis keys. Replacing this default setup with **[GenericJackson2JsonRedisSerializer](https://www.mindstick.com/forum/34569/json)** enables readable JSON representations and seamless deserialization.

## Spring Boot Redis Configuration

You can override default serialization by registering a custom `RedisTemplate` bean inside a configuration class.

```java
package com.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate template = new RedisTemplate<>();
        // Connect template to underlying Redis client factory
        template.setConnectionFactory(factory);

        // Set plain string serializer for key names
        template.setKeySerializer(new StringRedisSerializer());

        // Set JSON serializer for stored values
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());

        return template;
    }
}
```


---

Original Source: https://answers.mindstick.com/qa/117201/how-to-configure-custom-redis-serialization-in-spring-boot

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
