Example usage for org.springframework.core.serializer Deserializer deserialize

List of usage examples for org.springframework.core.serializer Deserializer deserialize

Introduction

In this page you can find the example usage for org.springframework.core.serializer Deserializer deserialize.

Prototype

T deserialize(InputStream inputStream) throws IOException;

Source Link

Document

Read (assemble) an object of type T from the given InputStream.

Usage

From source file:org.springdata.ehcache.convert.EhcacheMappingConverter.java

@Override
public <R> R read(Class<R> clazz, ByteArray source) {

    if (source.isEmpty()) {
        return null;
    }/*  w  w w  .  java  2 s  .  c  o  m*/

    Class<R> beanClassLoaderClass = transformClassToBeanClassLoaderClass(clazz);

    EhcachePersistentEntity<R> entity = (EhcachePersistentEntity<R>) mappingContext
            .getPersistentEntity(beanClassLoaderClass);
    if (entity == null) {
        throw new MappingException("No mapping metadata found for " + source.getClass());
    }

    Deserializer<R> deserializer = entity.getDeserializer();

    try {
        R newInstance = deserializer.deserialize(source.asStream());
        return newInstance;
    } catch (IOException e) {
        throw new MappingException("deserialization fail for " + beanClassLoaderClass, e);
    }
}