All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.damianwajser.serializer.CustomJdkRedisSerializer Maven / Gradle / Ivy

There is a newer version: 1.28.6
Show newest version
package com.github.damianwajser.serializer;

import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.data.redis.serializer.StringRedisSerializer;

public class CustomJdkRedisSerializer extends JdkSerializationRedisSerializer {
	private StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();

	@Override
	public byte[] serialize(Object source) {
		if(source instanceof String || source instanceof Number) {
			return stringRedisSerializer.serialize(source.toString());
		}
		return super.serialize(source);
	}

	@Override
	public Object deserialize(byte[] source) {
		try {
			return super.deserialize(source);
		} catch(SerializationException sex) {
			return stringRedisSerializer.deserialize(source);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy