Java Code Examples for org.springframework.util.SerializationUtils

The following examples show how to use org.springframework.util.SerializationUtils. These examples are extracted from open source projects. 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
private int fetchDataValuesPageSizeFromSystemSettings( final Context context ) throws SQLException
{
    int dataValuesPageSize = 0;

    String sql = "SELECT value FROM systemsetting WHERE name = '" + DATA_VALUES_SYNC_PAGE_SIZE_KEY +"';";
    try ( Statement stmt = context.getConnection().createStatement();
          ResultSet rs = stmt.executeQuery( sql ); )
    {
        if ( rs.next() )
        {
            dataValuesPageSize = (Integer) SerializationUtils.deserialize( rs.getBytes( "value" ) );
        }

        log.info( "Value found in SystemSettings: dataValuePageSize: " + dataValuesPageSize );
    }

    return dataValuesPageSize;
}
 
Example 2
Source Project: spring-analysis-note   Source File: CacheResultInterceptor.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
private static <T extends Throwable> T cloneException(T exception) {
	try {
		return (T) SerializationUtils.deserialize(SerializationUtils.serialize(exception));
	}
	catch (Exception ex) {
		return null;  // exception parameter cannot be cloned
	}
}
 
Example 3
Source Project: java-master   Source File: DevToolsRunner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run(String... args) {
    // null意味着是BootstrapClassLoader
    System.out.println("Object classloader:" + Object.class.getClassLoader());
    // RestartClassLoader
    System.out.println("ClassLoaderApplication classloader:"
            + ClassLoaderApplication.class.getClassLoader().getClass().getSimpleName());
    // AppClassLoader
    System.out.println("ClassLoaderApplication classloader parent:"
            + ClassLoaderApplication.class.getClassLoader().getParent().getClass().getSimpleName());
    // ExtClassLoader
    System.out.println("ClassLoaderApplication classloader parent's parent:"
            + ClassLoaderApplication.class.getClassLoader().getParent().getParent().getClass().getSimpleName());
    // UserBaseDto是已导入到IDE的项目其它模块类文件
    UserBaseDto userBaseDto = new UserBaseDto();
    System.out.println("userBaseDto object classloader:"
            + userBaseDto.getClass().getClassLoader().getClass().getSimpleName());
    byte[] bytes = SerializationUtils.serialize(userBaseDto);
    Object deserializeUserBaseDto = SerializationUtils.deserialize(bytes);
    System.out.println("deserialize userBaseDto object classloader:"
            + deserializeUserBaseDto.getClass().getClassLoader().getClass().getSimpleName());
    // userBaseDto = (UserBaseDto) deserializeUserBaseDto;

    deserializeUserBaseDto = SerializeUtils.deserialize(bytes);
    userBaseDto = (UserBaseDto) deserializeUserBaseDto;
    System.out.println(userBaseDto);
}
 
Example 4
Source Project: spring-graalvm-native   Source File: VetTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization() {
    Vet vet = new Vet();
    vet.setFirstName("Zaphod");
    vet.setLastName("Beeblebrox");
    vet.setId(123);
    Vet other = (Vet) SerializationUtils
            .deserialize(SerializationUtils.serialize(vet));
    assertThat(other.getFirstName()).isEqualTo(vet.getFirstName());
    assertThat(other.getLastName()).isEqualTo(vet.getLastName());
    assertThat(other.getId()).isEqualTo(vet.getId());
}
 
Example 5
Source Project: spring-graalvm-native   Source File: VetTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testSerialization() {
	Vet vet = new Vet();
	vet.setFirstName("Zaphod");
	vet.setLastName("Beeblebrox");
	vet.setId(123);
	Vet other = (Vet) SerializationUtils.deserialize(SerializationUtils.serialize(vet));
	assertThat(other.getFirstName()).isEqualTo(vet.getFirstName());
	assertThat(other.getLastName()).isEqualTo(vet.getLastName());
	assertThat(other.getId()).isEqualTo(vet.getId());
}
 
Example 6
Source Project: java-technology-stack   Source File: CacheResultInterceptor.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
private static <T extends Throwable> T cloneException(T exception) {
	try {
		return (T) SerializationUtils.deserialize(SerializationUtils.serialize(exception));
	}
	catch (Exception ex) {
		return null;  // exception parameter cannot be cloned
	}
}
 
Example 7
Source Project: n2o-framework   Source File: N2oSourceMergerFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <S> S merge(S source, S override) {
    List<SourceMerger> mergers = produceList(FactoryPredicates::isSourceAssignableFrom, source);
    S result = (S) SerializationUtils.deserialize(SerializationUtils.serialize(source));
    for (SourceMerger merger : mergers) {
        result = (S) merger.merge(result, override);
    }
    return result;
}
 
Example 8
Source Project: spring-init   Source File: VetTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testSerialization() {
    Vet vet = new Vet();
    vet.setFirstName("Zaphod");
    vet.setLastName("Beeblebrox");
    vet.setId(123);
    Vet other = (Vet) SerializationUtils
            .deserialize(SerializationUtils.serialize(vet));
    assertThat(other.getFirstName()).isEqualTo(vet.getFirstName());
    assertThat(other.getLastName()).isEqualTo(vet.getLastName());
    assertThat(other.getId()).isEqualTo(vet.getId());
}
 
Example 9
Source Project: MyBlog   Source File: MyRedisSessionDao.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    protected Serializable doCreate(Session session) {
        Serializable sessionId = generateSessionId(session);
        assignSessionId(session, sessionId);
//        session.setAttribute("user",session.get);
        byte[] keyByte = RedisKey.getKeyByte(RedisKey.SESSION_PRE, sessionId.toString());
        byte[] sessionByte = SerializationUtils.serialize(session);
        client.setEx(keyByte, sessionByte, SESSION_EXPIRE);
        return sessionId;
    }
 
Example 10
Source Project: MyBlog   Source File: MyRedisSessionDao.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Session doReadSession(Serializable sessionId) {
    if (sessionId == null) {
        return null;
    }
    byte[] keyByte = RedisKey.getKeyByte(RedisKey.SESSION_PRE, sessionId.toString());
    byte[] sessionByte = client.get(keyByte);
    return (Session) SerializationUtils.deserialize(sessionByte);
}
 
Example 11
Source Project: MyBlog   Source File: MyRedisSessionDao.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Session> getActiveSessions() {
    Set<byte[]> keyByteSet = client.keys((RedisKey.SESSION_PRE + "*").getBytes());
    Set<Session> sessionSet = Sets.newHashSet();
    for (byte[] keyByte : keyByteSet) {
        byte[] sessionByte = client.get(keyByte);
        Session session = (Session) SerializationUtils.deserialize(sessionByte);
        if (session != null) {
            sessionSet.add(session);
        }
    }
    return sessionSet;
}
 
Example 12
Source Project: lams   Source File: CacheResultInterceptor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T extends Throwable> T cloneException(T exception) {
	try {
		return (T) SerializationUtils.deserialize(SerializationUtils.serialize(exception));
	}
	catch (Exception ex) {
		return null;  // exception parameter cannot be cloned
	}
}
 
Example 13
Source Project: uflo   Source File: HistoryVariable.java    License: Apache License 2.0 5 votes vote down vote up
public void init(Context context){
	SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
	Session session=context.getSession();
	if(type.equals(VariableType.Blob) || type.equals(VariableType.Text)){
		HistoryBlob blob=(HistoryBlob)session.get(HistoryBlob.class,Long.valueOf(stringValue));
		variableObject=SerializationUtils.deserialize(blob.getBlobValue());
	}else if(type.equals(VariableType.String)){
		variableObject=stringValue;
	}else if(type.equals(VariableType.Date)){
		try {
			variableObject=sd.parse(stringValue);
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}else if(type.equals(VariableType.Integer)){
		variableObject=Integer.valueOf(stringValue);
	}else if(type.equals(VariableType.Character)){
		variableObject=Character.valueOf((char)(stringValue.getBytes()[0]));
	}else if(type.equals(VariableType.Double)){
		variableObject=Double.valueOf(stringValue);
	}else if(type.equals(VariableType.Float)){
		variableObject=Float.valueOf(stringValue);
	}else if(type.equals(VariableType.Long)){
		variableObject=Long.valueOf(stringValue);
	}else if(type.equals(VariableType.Byte)){
		variableObject=Byte.valueOf(stringValue);
	}else if(type.equals(VariableType.Short)){
		variableObject=Short.valueOf(stringValue);
	}else if(type.equals(VariableType.Boolean)){
		variableObject=Boolean.valueOf(stringValue);
	}
}
 
Example 14
@SuppressWarnings("unchecked")
private static <T extends Throwable> T cloneException(T exception) {
	try {
		return (T) SerializationUtils.deserialize(SerializationUtils.serialize(exception));
	}
	catch (Exception ex) {
		return null;  // exception parameter cannot be cloned
	}
}
 
Example 15
Source Project: yes-cart   Source File: WsMessage.java    License: Apache License 2.0 5 votes vote down vote up
public WsMessage(final Message message) {
    this.source = message.getSource();
    this.subject = message.getSubject();
    if (message.getTargets() != null) {
        this.targets = new ArrayList<>(message.getTargets());
    }
    this.payload = SerializationUtils.serialize(message.getPayload());
}
 
Example 16
Source Project: yes-cart   Source File: RestMessage.java    License: Apache License 2.0 5 votes vote down vote up
public RestMessage(final Message message) {
    this.source = message.getSource();
    this.subject = message.getSubject();
    if (message.getTargets() != null) {
        this.targets = new ArrayList<>(message.getTargets());
    }
    this.payload = SerializationUtils.serialize(message.getPayload());
}
 
Example 17
Source Project: ankush   Source File: EventHistory.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Method to get the events.
 * @return
 */
@Transient
public Event getEvent() {
	if (getEventBytes() == null) {
		return null;
	}
	return (Event) SerializationUtils.deserialize(getEventBytes());
}
 
Example 18
Source Project: ankush   Source File: Template.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Method to get data as Linked Hash Map.
 * 
 * @return {@link ClusterConf}
 */
@Transient
public ClusterConfig getData() {
	if (getDataBytes() == null) {
		return null;
	}
	try {
		return (ClusterConfig) SerializationUtils.deserialize(getDataBytes());
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 19
Source Project: ankush   Source File: Template.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Method to set the ClusterConf as bytes in db.
 * 
 */
public void setData(ClusterConfig data) {
	if (data != null) {
		data.setState(Constant.Cluster.State.ERROR);
		setDataBytes(SerializationUtils.serialize(data));
	}
}
 
Example 20
Source Project: jdal   Source File: SerializableProxyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializablePostProcessor() {
	byte[] ser = SerializationUtils.serialize(configurableBean);
	ConfigurableBean cb = (ConfigurableBean) SerializationUtils.deserialize(ser);
	assertEquals(cb.getNoSerializableBean(), configurableBean.getNoSerializableBean());
	ser = SerializationUtils.serialize(autowiredBean);
    AutowiredBean ab = (AutowiredBean) SerializationUtils.deserialize(ser);
    assertEquals(autowiredBean.getNoSerializableBean(), ab.getNoSerializableBean());
}
 
Example 21
Source Project: n2o-framework   Source File: CompileUtil.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T copy(T cloningObject) {
    return (T) SerializationUtils.deserialize(SerializationUtils.serialize(cloningObject));
}
 
Example 22
Source Project: n2o-framework   Source File: CopyOperation.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public S execute(CompileContext<?, ?> context, DataSet data, Supplier<S> supplier, CompileProcessor compileProcessor,
                 BindProcessor bindProcessor,
                 ValidateProcessor validateProcessor) {
    return (S) SerializationUtils.deserialize(SerializationUtils.serialize(supplier.get()));
}
 
Example 23
Source Project: spring-boot-react-blog   Source File: CookieUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static String serialize(Object object) {
    return Base64.getUrlEncoder()
            .encodeToString(SerializationUtils.serialize(object));
}
 
Example 24
Source Project: spring-boot-react-blog   Source File: CookieUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> T deserialize(Cookie cookie, Class<T> cls) {
    return cls.cast(SerializationUtils.deserialize(
                    Base64.getUrlDecoder().decode(cookie.getValue())));
}
 
Example 25
Source Project: EasyTransaction   Source File: SpringObjectSerialization.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public byte[] serialization(Object obj) {
	return SerializationUtils.serialize(obj);
}
 
Example 26
Source Project: EasyTransaction   Source File: SpringObjectSerialization.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T deserialize(byte[] bytes) {
	return (T)SerializationUtils.deserialize(bytes);
}
 
Example 27
@Override
public Object read(byte[] payload, Class<?> targetType) {
	return SerializationUtils.deserialize(payload);
}
 
Example 28
@Override
public byte[] write(Object target) {
	return SerializationUtils.serialize(target);
}
 
Example 29
Source Project: MyBlog   Source File: MyRedisSessionDao.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void update(Session session) throws UnknownSessionException {
    byte[] keyByte = RedisKey.getKeyByte(RedisKey.SESSION_PRE, session.getId().toString());
    byte[] sessionByte = SerializationUtils.serialize(session);
    client.setEx(keyByte, sessionByte, SESSION_EXPIRE);
}
 
Example 30
Source Project: uflo   Source File: TextVariable.java    License: Apache License 2.0 4 votes vote down vote up
public void initValue(Context context){
	Session session=context.getSession();
	blob=(Blob)session.get(Blob.class,blobId);
	text=(String)SerializationUtils.deserialize(blob.getBlobValue());
}