org.springframework.data.redis.serializer.SerializationException Java Examples

The following examples show how to use org.springframework.data.redis.serializer.SerializationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageSerializer.java    From servicecomb-pack with Apache License 2.0 6 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws SerializationException {
  try {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);

    Object object = objectInputStream.readObject();

    objectInputStream.close();

    return object;
  } catch (Exception e) {
    LOG.error("deserialize Exception = [{}]", e.getMessage(), e);
  }

  return null;
}
 
Example #2
Source File: MessageSerializer.java    From servicecomb-pack with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] serialize(Object data) throws SerializationException {
  try {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream outputStream = new ObjectOutputStream(byteArrayOutputStream);
    outputStream.writeObject(data);

    byte[] bytes = byteArrayOutputStream.toByteArray();

    outputStream.close();

    return bytes;
  } catch (Exception e) {
    LOG.error("serialize Exception = [{}]", e.getMessage(), e);
  }

  return null;
}
 
Example #3
Source File: JaxbPayloadSerializer.java    From redisq with MIT License 6 votes vote down vote up
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);
    }
}
 
Example #4
Source File: JaxbPayloadSerializer.java    From redisq with MIT License 6 votes vote down vote up
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);
    }
}
 
Example #5
Source File: KryoRedisSerializer.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] serialize(T t) throws SerializationException {
    if (t == null) {
        return EMPTY_BYTE_ARRAY;
    }

    Kryo kryo = kryos.get();
    kryo.setReferences(false);
    kryo.register(clazz);

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         Output output = new Output(baos)) {
        kryo.writeClassAndObject(output, t);
        output.flush();
        return baos.toByteArray();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    return EMPTY_BYTE_ARRAY;
}
 
Example #6
Source File: KryoRedisSerializer.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
@Override
public T deserialize(byte[] bytes) throws SerializationException {
    if (bytes == null || bytes.length <= 0) {
        return null;
    }

    Kryo kryo = kryos.get();
    kryo.setReferences(false);
    kryo.register(clazz);

    try (Input input = new Input(bytes)) {
        return (T) kryo.readClassAndObject(input);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    return null;
}
 
Example #7
Source File: KryoRedisSerializer.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
@Override
public T deserialize(byte[] bytes) throws SerializationException {
    if (bytes == null || bytes.length <= 0) {
        return null;
    }

    Kryo kryo = kryos.get();
    kryo.setReferences(false);
    kryo.register(clazz);

    try (Input input = new Input(bytes)) {
        return (T) kryo.readClassAndObject(input);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    return null;
}
 
Example #8
Source File: Jackson2PayloadSerializer.java    From redisq with MIT License 5 votes vote down vote up
public <T> T deserialize(String payload, Class<T> type) throws SerializationException {
    if (payload == null) {
        return null;
    }

    try {
        return mapper.readValue(payload, type);
    } catch (IOException e) {
        throw new SerializationException("Could not serialize object using Jackson.", e);
    }
}
 
Example #9
Source File: FastJsonRedisSerializer.java    From SpringBoot-Study with Apache License 2.0 5 votes vote down vote up
/**
 * εεΊεˆ—εŒ–
 *
 * @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);
}
 
Example #10
Source File: FastJsonJsonSerializer.java    From phone with Apache License 2.0 5 votes vote down vote up
public T deserialize(byte[] bytes) throws SerializationException {
	if (ArrayUtils.isEmpty(bytes)) {
		return null;
	}
	try {
		return JSON.parseObject(bytes, javaType);
	} catch (Exception ex) {
		throw new SerializationException("Could not read JSON: " + ex.getMessage(), ex);
	}
}
 
Example #11
Source File: CursorKeyRedisSerializer.java    From fahrschein with Apache License 2.0 5 votes vote down vote up
@Override
public RedisCursorKey deserialize(final byte[] bytes) throws SerializationException {
    final String[] values = CODEC.deserialize(bytes);

    if (values == null) {
        return null;
    }

    return new RedisCursorKey(values[0], values[1], values[2]);
}
 
Example #12
Source File: FastJson2JsonRedisSerializer.java    From mysiteforme with Apache License 2.0 5 votes vote down vote up
public T deserialize(byte[] bytes) throws SerializationException {
    if (bytes == null || bytes.length <= 0) {
        return null;
    }
    String str = new String(bytes, DEFAULT_CHARSET);

    return JSON.parseObject(str, clazz);
}
 
Example #13
Source File: Jackson2PayloadSerializer.java    From redisq with MIT License 5 votes vote down vote up
public String serialize(Object payload) throws SerializationException {
    try {
        return mapper.writeValueAsString(payload);
    } catch (IOException e) {
        throw new SerializationException("Could not serialize object using Jackson.", e);
    }
}
 
Example #14
Source File: JacksonPayloadSerializer.java    From redisq with MIT License 5 votes vote down vote up
public <T> T deserialize(String payload, Class<T> type) throws SerializationException {
    if (payload == null) {
        return null;
    }

    try {
        return mapper.readValue(payload, type);
    } catch (IOException e) {
        throw new SerializationException("Could not serialize object using Jackson.", e);
    }
}
 
Example #15
Source File: JacksonPayloadSerializer.java    From redisq with MIT License 5 votes vote down vote up
public String serialize(Object payload) throws SerializationException {
    try {
        return mapper.writeValueAsString(payload);
    } catch (IOException e) {
        throw new SerializationException("Could not serialize object using Jackson.", e);
    }
}
 
Example #16
Source File: FastJsonJsonSerializer.java    From phone with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(Object t) throws SerializationException {

		if (t == null) {
			return EMPTY_ARRAY;
		}
		try {
			return JSON.toJSONBytes(t);
		} catch (Exception ex) {
			throw new SerializationException("Could not write JSON: " + ex.getMessage(), ex);
		}
	}
 
Example #17
Source File: GenericFastJsonRedisSerializer.java    From uavstack with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #18
Source File: Fastjson2JsonRedisSerializer.java    From notes with Apache License 2.0 5 votes vote down vote up
@Override
public T deserialize(byte[] bytes) throws SerializationException {
    if (bytes == null || bytes.length <= 0) {
        return null;
    }
    String str = new String(bytes, DEFAULT_CHARSET);

    return (T) JSON.parseObject(str, clazz);

}
 
Example #19
Source File: CursorRedisSerializer.java    From fahrschein with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor deserialize(final byte[] bytes) throws SerializationException {
    final String[] values = CODEC.deserialize(bytes);

    if (values == null) {
        return null;
    }

    return new Cursor(values[0], values[1]);
}
 
Example #20
Source File: FastJsonRedisSerializer.java    From ywh-frame with GNU General Public License v3.0 5 votes vote down vote up
@Override
public byte[] serialize(T t) throws SerializationException {
    if (t == null) {
        return new byte[0];
    }
    return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);
}
 
Example #21
Source File: FastJsonRedisSerializer.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #22
Source File: RedisObjectSerializer.java    From mysiteforme with Apache License 2.0 5 votes vote down vote up
public Object deserialize(byte[] bytes) {
    if (isEmpty(bytes)) {
        return null;
    }
    try {
        return deserializer.convert(bytes);
    } catch (Exception ex) {
        throw new SerializationException("Cannot deserialize", ex);
    }
}
 
Example #23
Source File: FastJsonRedisSerializer.java    From java-tutorial with MIT License 5 votes vote down vote up
@Override
public T deserialize(byte[] bytes) throws SerializationException {

    if (null == bytes || bytes.length <= 0) {
        return null;
    }
    String str = new String(bytes, DEFAULT_CHARSET);
    return (T) JSON.parseObject(str, clazz);
}
 
Example #24
Source File: FastJsonRedisSerializer.java    From java-tutorial with MIT License 5 votes vote down vote up
@Override
public byte[] serialize(T t) throws SerializationException {
    if (null == t) {
        return new byte[0];
    }
    return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);
}
 
Example #25
Source File: FastJsonRedisSerializer.java    From SpringBootLearn with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(T t) throws SerializationException {
    if (null == t) {
        return new byte[0];
    }
    return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);
}
 
Example #26
Source File: Fastjson2JsonRedisSerializer.java    From notes with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(T t) throws SerializationException {
    if (t == null) {
        return new byte[0];
    }
    return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);
}
 
Example #27
Source File: CustomJdkSerializationRedisSerializer.java    From oauth-server with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(Object object) {
    if (object == null) {
        return emptyArray;
    }
    try {
        return serializer.convert(object);
    } catch (Exception ex) {
        throw new SerializationException("Cannot serialize", ex);
    }
}
 
Example #28
Source File: J2CacheSerializer.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws SerializationException {
	try {
		return SerializationUtils.deserialize(bytes);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
Example #29
Source File: J2CacheSerializer.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object t) throws SerializationException {	
	try {
		return SerializationUtils.serialize(t);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
Example #30
Source File: J2CacheSerializer.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws SerializationException {
	try {
		return SerializationUtils.deserialize(bytes);
	} catch (IOException e) {
		e.printStackTrace();
		FSTUtil.rethrow(e);
	}
	return null;
}