本文整理汇总了Java中org.springframework.data.redis.serializer.SerializationException类的典型用法代码示例。如果您正苦于以下问题:Java SerializationException类的具体用法?Java SerializationException怎么用?Java SerializationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializationException类属于org.springframework.data.redis.serializer包,在下文中一共展示了SerializationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: redisTemplate
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Bean
@Primary
RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory rcf) {
AitLogger.debug(logger, "Serializer overriding ");
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(rcf);
GenericJackson2JsonRedisSerializer valSerializer = new GenericJackson2JsonRedisSerializer();
template.setValueSerializer(valSerializer);
template.setKeySerializer(new RedisSerializer<Object>() {
@Override
public byte[] serialize(Object t) throws SerializationException {
return (t == null ? null : (":" + t.toString()).getBytes());
}
@Override
public Object deserialize(byte[] bytes) throws SerializationException {
return (bytes == null ? null : new String(bytes));
}
});
template.setHashValueSerializer(valSerializer);
return template;
}
示例2: deserialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Override
public Execution deserialize(byte[] bytes) throws SerializationException {
try {
return super.deserialize(bytes);
} catch (SerializationException e) {
if (ignoreDeserializationFailures) {
if (deserializationFailuresCache.add(e.getMessage())) {
log.warn("Ignoring invalid JSON: {}.", e.getMessage());
}
if (deserializationFailuresCache.size() > 1000) {
deserializationFailuresCache.clear();
}
return null;
}
throw e;
}
}
示例3: serialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Override
public byte[] serialize(Object obj) throws SerializationException {
final Kryo kryo = KryoHolder.borrow();
Output output = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
output = new Output(baos);
kryo.writeClassAndObject(output, obj);
return output.toBytes();
} finally {
if (output != null) {
output.close();
}
KryoHolder.release(kryo);
}
}
示例4: deserialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Override
public Object deserialize(byte[] bytes) throws SerializationException {
if (bytes == null || bytes.length == 0)
return null;
final Kryo kryo = KryoHolder.borrow();
Input input = null;
try {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
input = new Input(bais);
return kryo.readClassAndObject(input);
} finally {
if (input != null) {
input.close();
}
KryoHolder.release(kryo);
}
}
示例5: serialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
public String serialize(Object payload) {
Class<?> payloadType = payload.getClass();
try {
JAXBContext context = JAXBContext.newInstance(payloadType);
Marshaller marshaller = context.createMarshaller();
ByteArrayOutputStream payloadAsXml = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
marshaller.marshal(payload, payloadAsXml);
return new String(payloadAsXml.toByteArray());
} catch (JAXBException e) {
throw new SerializationException("JAXB error while serializing object.", e);
}
}
示例6: deserialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
public <T> T deserialize(String payload, Class<T> payloadType) {
try {
JAXBContext context = JAXBContext.newInstance(payloadType);
Unmarshaller unmarshaller = context.createUnmarshaller();
if (log.isDebugEnabled()) {
// input stream can only be read once.
log.debug("Message payload content as JAXB XML:");
log.debug("++++++++++++++++++++++++++++++++++");
log.debug(payload);
log.debug("----------------------------------");
}
ByteArrayInputStream payloadStream = new ByteArrayInputStream(payload.getBytes());
JAXBElement<T> element = unmarshaller.unmarshal(new StreamSource(payloadStream), payloadType);
return (element == null) ? null : element.getValue();
} catch (JAXBException e) {
throw new SerializationException("Could not deserialize payload.", e);
}
}
示例7: serialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Override
public byte[] serialize(T graph) throws SerializationException {
if (GzipRedisSerializer.log.isTraceEnabled())
GzipRedisSerializer.log.trace("객체를 직렬화 후에 압축을 수행합니다...");
if (graph == null)
return new byte[0];
try {
byte[] bytes = innerSerializer.serialize(graph);
@Cleanup ByteArrayOutputStream bos = new ByteArrayOutputStream();
@Cleanup GZIPOutputStream gzip = new GZIPOutputStream(bos);
gzip.write(bytes);
gzip.close();
byte[] result = bos.toByteArray();
if (GzipRedisSerializer.log.isTraceEnabled())
GzipRedisSerializer.log.trace("객체를 직렬화 후에 압축했습니다. 기존=[{}], 압축후=[{}]", bytes.length, result.length);
return result;
} catch (Exception e) {
throw new SerializationException("Gzip 압축 실패", e);
}
}
示例8: serialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Override
public byte[] serialize(T t) throws SerializationException {
if (t == null) {
return new byte[0];
}
try {
return JSON.toJSONBytes(t, fastJsonConfig.getSerializeConfig(), fastJsonConfig.getSerializerFeatures());
} catch (Exception ex) {
throw new SerializationException("Could not serialize: " + ex.getMessage(), ex);
}
}
示例9: deserialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Override
public T deserialize(byte[] bytes) throws SerializationException {
if (bytes == null || bytes.length == 0) {
return null;
}
try {
return (T) JSON.parseObject(bytes, type, fastJsonConfig.getFeatures());
} catch (Exception ex) {
throw new SerializationException("Could not deserialize: " + ex.getMessage(), ex);
}
}
示例10: serialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Override
public byte[] serialize(Object object) throws SerializationException {
if (object == null) {
return new byte[0];
}
try {
return JSON.toJSONBytes(object, SerializerFeature.WriteClassName);
} catch (Exception ex) {
throw new SerializationException("Could not serialize: " + ex.getMessage(), ex);
}
}
示例11: deserialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Override
public Object deserialize(byte[] bytes) throws SerializationException {
if (bytes == null || bytes.length == 0) {
return null;
}
try {
return JSON.parseObject(new String(bytes, IOUtils.UTF8), Object.class, defaultRedisConfig);
} catch (Exception ex) {
throw new SerializationException("Could not deserialize: " + ex.getMessage(), ex);
}
}
示例12: test_5
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
@Test(expected = SerializationException.class)
public void test_5() {
User user = new User(1, "土豆", 25);
byte[] serializedValue = serializer.serialize(user);
Arrays.sort(serializedValue); // corrupt serialization result
serializer.deserialize(serializedValue);
}
示例13: deserialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
/**
* 反序列化
*
* @param bytes
* @return
* @throws SerializationException
*/
public T deserialize(byte[] bytes) throws SerializationException {
if (bytes == null || bytes.length <= 0) {
return null;
}
String str = new String(bytes, charset);
if (clazz == null) {
return (T) JSON.parse(str);
}
return (T) JSON.parseObject(str, clazz);
}
示例14: deserialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
/**
* 反序列化
*/
@Override
public Object deserialize(byte[] bytes) {
if (isEmpty(bytes)) {
return null;
}
try {
return deserializer.convert(bytes);
} catch (Exception ex) {
throw new SerializationException("Cannot deserialize", ex);
}
}
示例15: deserialize
import org.springframework.data.redis.serializer.SerializationException; //导入依赖的package包/类
public Object deserialize(byte[] bytes) {
if (isEmpty(bytes)) {
return null;
}
try {
return deserializer.convert(bytes);
} catch (Exception ex) {
throw new SerializationException("Cannot deserialize", ex);
}
}