Java Code Examples for org.springframework.util.SerializationUtils#deserialize()

The following examples show how to use org.springframework.util.SerializationUtils#deserialize() . 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: V2_35_2__Update_data_sync_job_parameters_with_system_setting_value.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 File: DevToolsRunner.java    From java-master with 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 3
Source File: CacheResultInterceptor.java    From spring4-understanding with Apache License 2.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 4
Source File: Template.java    From ankush with 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 5
Source File: SerializableProxyTest.java    From jdal with 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 6
Source File: CacheResultInterceptor.java    From lams with 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 7
Source File: MyRedisSessionDao.java    From MyBlog with 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 8
Source File: MyRedisSessionDao.java    From MyBlog with 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 9
Source File: EventHistory.java    From ankush with 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 10
Source File: N2oSourceMergerFactory.java    From n2o-framework with 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 11
Source File: CacheResultInterceptor.java    From java-technology-stack with 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 12
Source File: VetTests.java    From spring-graalvm-native with 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 13
Source File: VetTests.java    From spring-graalvm-native with 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 14
Source File: CacheResultInterceptor.java    From spring-analysis-note with 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 15
Source File: SpringObjectSerialization.java    From EasyTransaction with 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 16
Source File: WsMessage.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
public <T extends Serializable> T getPayloadObject() {
    return (T) SerializationUtils.deserialize(this.payload);
}
 
Example 17
Source File: CompileUtil.java    From n2o-framework with 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 18
Source File: ProxySerializationTest.java    From jdal with Apache License 2.0 4 votes vote down vote up
@Test
public void testUISerialization() {
	byte[] ser = SerializationUtils.serialize(testUI);
	TestUI deserialized = (TestUI) SerializationUtils.deserialize(ser);
	Assert.assertEquals(testUI.getClass(), deserialized.getClass());
}
 
Example 19
Source File: RestMessage.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
public <T extends Serializable> T getPayloadObject() {
    return (T) SerializationUtils.deserialize(this.payload);
}
 
Example 20
Source File: CloneUtils.java    From spring-cloud-contract with Apache License 2.0 2 votes vote down vote up
/**
 * Clones an object if it's serializable.
 * @param object to clone
 * @return a clone of the object
 */
public static Object clone(Object object) {
	byte[] serializedObject = SerializationUtils.serialize(object);
	return SerializationUtils.deserialize(serializedObject);
}