Java 类org.springframework.core.serializer.support.SerializationFailedException 实例源码

项目:oma-riista-web    文件:HttpSessionConfig.java   
private static GenericConversionService safeConversionService() {
    final GenericConversionService converter = new GenericConversionService();
    converter.addConverter(Object.class, byte[].class, new SerializingConverter());

    final DeserializingConverter byteConverter = new DeserializingConverter();
    converter.addConverter(byte[].class, Object.class, (byte[] bytes) -> {
        try {
            return byteConverter.convert(bytes);
        } catch (SerializationFailedException e) {
            LOG.error("Could not extract attribute: {}", e.getMessage());
            return null;
        }
    });

    return converter;
}
项目:microservices-transactions-tcc    文件:CompositeTransactionManagerKafkaImpl.java   
@SuppressWarnings("unchecked")
@Override
public List<EntityCommand<?>> fetch(String txId) {
    List<EntityCommand<?>> transactionOperations = new ArrayList<EntityCommand<?>>();

    Map<String, Object> consumerConfigs = (Map<String, Object>)configuration.get("kafkaConsumerConfiguration");
    consumerConfigs.put(ConsumerConfig.GROUP_ID_CONFIG, UUID.randomUUID().toString());

    KafkaConsumer<String, String> kafkaConsumer = new KafkaConsumer<String, String>(consumerConfigs);
    kafkaConsumer.subscribe(Arrays.asList(txId));

    ConsumerRecords<String, String> records = kafkaConsumer.poll(kafkaConsumerPollTimeout);
    for (ConsumerRecord<String, String> record : records){
        LOG.info("offset = {}, key = {}, value = {}", record.offset(), record.key(), record.value());
        try {
            transactionOperations.add(serializer.readFromString(record.value()));
        } catch (SerializationFailedException e) {
            LOG.error("Unable to deserialize [{}] because of: {}", record.value(), e.getMessage());
        }
    }

    kafkaConsumer.close();

    return transactionOperations;
}
项目:microservices-transactions-tcc    文件:AbstractEntityCommandJsonSerializer.java   
@Override
public String writeToString(EntityCommand<T> object) throws SerializationFailedException {
    try {
        return jacksonMapper.writeValueAsString(object);
    } catch (JsonProcessingException e) {
        throw new SerializationFailedException("Error performing EntityCommand serialization", e);
    }
}
项目:spring4-understanding    文件:SerializationConverterTests.java   
@Test
public void nonSerializableObject() {
    SerializingConverter toBytes = new SerializingConverter();
    try {
        toBytes.convert(new Object());
        fail("Expected IllegalArgumentException");
    }
    catch (SerializationFailedException e) {
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof IllegalArgumentException);
    }
}
项目:spring4-understanding    文件:SerializationConverterTests.java   
@Test
public void nonSerializableField() {
    SerializingConverter toBytes = new SerializingConverter();
    try {
        toBytes.convert(new UnSerializable());
        fail("Expected SerializationFailureException");
    }
    catch (SerializationFailedException e) {
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof NotSerializableException);
    }
}
项目:class-guard    文件:SerializationConverterTests.java   
@Test
public void nonSerializableObject() {
    SerializingConverter toBytes = new SerializingConverter();
    try {
        toBytes.convert(new Object());
        fail("Expected IllegalArgumentException");
    }
    catch (SerializationFailedException e) {
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof IllegalArgumentException);
    }
}
项目:class-guard    文件:SerializationConverterTests.java   
@Test
public void nonSerializableField() {
    SerializingConverter toBytes = new SerializingConverter();
    try {
        toBytes.convert(new UnSerializable());
        fail("Expected SerializationFailureException");
    }
    catch (SerializationFailedException e) {
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof NotSerializableException);
    }
}
项目:microservices-transactions-tcc    文件:AbstractEntityCommandJsonSerializer.java   
@Override
public byte[] write(EntityCommand<T> object) throws SerializationFailedException {
    return writeToString(object).getBytes();
}
项目:microservices-transactions-tcc    文件:AbstractEntityCommandJsonSerializer.java   
@Override
public EntityCommand<T> read(byte[] bytes) throws SerializationFailedException {
    return readFromString(new String(bytes));
}
项目:microservices-transactions-tcc    文件:AbstractEntityCommandJsonSerializer.java   
@Override
public abstract EntityCommand<T> readFromString(String chars) throws SerializationFailedException;
项目:spring4-understanding    文件:SerializationConverterTests.java   
@Test(expected = SerializationFailedException.class)
public void deserializationFailure() {
    DeserializingConverter fromBytes = new DeserializingConverter();
    fromBytes.convert("Junk".getBytes());
}
项目:class-guard    文件:SerializationConverterTests.java   
@Test(expected = SerializationFailedException.class)
public void deserializationFailure() {
    DeserializingConverter fromBytes = new DeserializingConverter();
    fromBytes.convert("Junk".getBytes());
}
项目:microservices-transactions-tcc    文件:Serializer.java   
byte[] write(T object) throws SerializationFailedException;
项目:microservices-transactions-tcc    文件:Serializer.java   
String writeToString(T object) throws SerializationFailedException;
项目:microservices-transactions-tcc    文件:Serializer.java   
T read(byte[] bytes) throws SerializationFailedException;
项目:microservices-transactions-tcc    文件:Serializer.java   
T readFromString(String chars) throws SerializationFailedException;