DATAREDIS-925 - Add and register binary read/write converter for UUID.
Original pull request: #444.
This commit is contained in:
committed by
Mark Paluch
parent
321199c084
commit
70cb773afe
@@ -21,6 +21,7 @@ import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterFactory;
|
||||
@@ -270,4 +271,35 @@ final class BinaryConverters {
|
||||
throw new IllegalArgumentException(String.format("Cannot parse date out of %s", Arrays.toString(source)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @since 2.2
|
||||
*/
|
||||
@WritingConverter
|
||||
static class UuidToBytesConverter extends StringBasedConverter implements Converter<UUID, byte[]> {
|
||||
|
||||
@Override
|
||||
public byte[] convert(UUID source) {
|
||||
return fromString(source.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @since 2.2
|
||||
*/
|
||||
@ReadingConverter
|
||||
static class BytesToUuidConverter extends StringBasedConverter implements Converter<byte[], UUID> {
|
||||
|
||||
@Override
|
||||
public UUID convert(byte[] source) {
|
||||
|
||||
if (ObjectUtils.isEmpty(source)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return UUID.fromString(toString(source));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public class RedisCustomConversions extends org.springframework.data.convert.Cus
|
||||
converters.add(new BinaryConverters.BytesToBooleanConverter());
|
||||
converters.add(new BinaryConverters.DateToBytesConverter());
|
||||
converters.add(new BinaryConverters.BytesToDateConverter());
|
||||
converters.add(new BinaryConverters.UuidToBytesConverter());
|
||||
converters.add(new BinaryConverters.BytesToUuidConverter());
|
||||
converters.addAll(Jsr310Converters.getConvertersToRegister());
|
||||
|
||||
STORE_CONVERTERS = Collections.unmodifiableList(converters);
|
||||
|
||||
Reference in New Issue
Block a user