Example usage for org.springframework.util SerializationUtils serialize

List of usage examples for org.springframework.util SerializationUtils serialize

Introduction

In this page you can find the example usage for org.springframework.util SerializationUtils serialize.

Prototype

@Nullable
public static byte[] serialize(@Nullable Object object) 

Source Link

Document

Serialize the given object to a byte array.

Usage

From source file:lpp.rabbitmq.spring.MessageConverter.java

protected Message createMessage(Object arg0, MessageProperties arg1) {
    return new Message(SerializationUtils.serialize(arg0), arg1);
}

From source file:com.searchbox.framework.model.AttributeEntity.java

public AttributeEntity setValue(Object value) {
    if (value != null) {
        if (type == null) {
            type = value.getClass();/*from w w w .j  a va2s.  c o  m*/
        }
        LOGGER.debug("Adding object of type {}", value.getClass());
        try {
            this.valueAsByteArray = SerializationUtils.serialize(value);
        } catch (Exception e) {
            LOGGER.error("Could not serialize value: " + this, e);
        }
    }
    return this;
}

From source file:serialization.ProxySerializationTest.java

private Object serialize(Object obj) {
    byte[] ser = SerializationUtils.serialize(obj);
    if (log.isDebugEnabled())
        log.debug("Serialized [" + ser.length + "] bytes");
    return SerializationUtils.deserialize(ser);
}

From source file:com.onedrive.api.support.SerializatorAccessTokenListener.java

public void onAccessTokenReceived(OneDrive reference, AccessToken accessToken) {
    File file = new File(getApplicationFolder(), getFileName(reference));
    String existing = tokens.get(file.getName());
    if (existing == null || !existing.equals(accessToken.getAccessToken())) {
        try {//w w w.  j  a v a 2 s.c o m
            Files.createDirectories(file.getParentFile().toPath());
            FileOutputStream fos = new FileOutputStream(file, false);
            fos.write(SerializationUtils.serialize(accessToken));
            fos.close();
            tokens.put(file.getName(), accessToken.getAccessToken());
            System.out.println("Access Token Persisted: " + file.getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.zxy.commons.cache.RedisCache.java

@Override
public ValueWrapper get(final Object key) {
    return redisTemplate.execute(new RedisCallback<ValueWrapper>() {
        public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException {

            byte[] keyb = SerializationUtils.serialize(key);
            byte[] value = connection.get(keyb);
            if (value == null) {
                return null;
            }/* w  w w  .j a v  a  2 s  .  c  om*/
            return new SimpleValueWrapper(SerializationUtils.deserialize(value));

        }
    });
}

From source file:com.example.session.domain.model.Cart.java

/**
 * ?????//from   www  . j  av a 2 s.c  o m
 * 
 * @param cart
 * @return
 */
public String calcSignature() {
    byte[] serialized = SerializationUtils.serialize(this);
    byte[] signature = null;
    try {
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        signature = messageDigest.digest(serialized);
    } catch (NoSuchAlgorithmException ignored) {
    }
    return new String(Base64.encode(signature));
}

From source file:serialization.ProxySerializationTest.java

@Test
public void testUISerialization() {
    byte[] ser = SerializationUtils.serialize(testUI);
    TestUI deserialized = (TestUI) SerializationUtils.deserialize(ser);
    Assert.assertEquals(testUI.getClass(), deserialized.getClass());
}

From source file:org.terasoluna.gfw.common.message.ResultMessageTest.java

@Test
public void test10() {
    try {// w w w .java2  s .com
        byte[] serialized = SerializationUtils.serialize(ResultMessage.fromText("foo"));
        SerializationUtils.deserialize(serialized);
    } catch (SerializationFailedException e) {
        fail();
    }
}

From source file:com.glaf.shiro.cache.zookeeper.ZooKeeperCache.java

public V put(K key, V value) throws CacheException {
    byte[] data = SerializationUtils.serialize(value);
    try {//from  w  w  w  . ja  v  a2 s  .  c o m
        String path = groupName + "/" + key;
        logger.debug("cache key:" + path);
        zkClient.create().withMode(CreateMode.PERSISTENT).forPath(path, data);
    } catch (Exception ex) {
        ex.printStackTrace();
        if (logger.isDebugEnabled()) {
            logger.debug(ex);
        }
    }
    return null;
}

From source file:com.zxy.commons.cache.RedisCache.java

@Override
public void put(Object key, Object value) {
    redisTemplate.execute(new RedisCallback<Long>() {
        public Long doInRedis(RedisConnection connection) throws DataAccessException {
            byte[] keyb = SerializationUtils.serialize(key);
            byte[] valueb = SerializationUtils.serialize(value);
            connection.set(keyb, valueb);
            if (expires > 0) {
                connection.expire(keyb, expires);
            }// ww  w . ja  va 2 s. c  o m
            return 1L;
        }
    });

}