org.springframework.util.SerializationUtils Java Examples
The following examples show how to use
org.springframework.util.SerializationUtils.
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 |
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: MyRedisSessionDao.java From MyBlog with Apache License 2.0 | 5 votes |
@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 #3
Source File: CacheResultInterceptor.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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: HistoryVariable.java From uflo with Apache License 2.0 | 5 votes |
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 #5
Source File: WsMessage.java From yes-cart with Apache License 2.0 | 5 votes |
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 #6
Source File: RestMessage.java From yes-cart with Apache License 2.0 | 5 votes |
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 #7
Source File: CacheResultInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
@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 #8
Source File: MyRedisSessionDao.java From MyBlog with Apache License 2.0 | 5 votes |
@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 #9
Source File: MyRedisSessionDao.java From MyBlog with Apache License 2.0 | 5 votes |
@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 #10
Source File: EventHistory.java From ankush with GNU Lesser General Public License v3.0 | 5 votes |
/** * Method to get the events. * @return */ @Transient public Event getEvent() { if (getEventBytes() == null) { return null; } return (Event) SerializationUtils.deserialize(getEventBytes()); }
Example #11
Source File: Template.java From ankush with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 #12
Source File: CacheResultInterceptor.java From spring-analysis-note with MIT License | 5 votes |
@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 #13
Source File: DevToolsRunner.java From java-master with Apache License 2.0 | 5 votes |
@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 #14
Source File: VetTests.java From spring-graalvm-native with Apache License 2.0 | 5 votes |
@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 #15
Source File: VetTests.java From spring-graalvm-native with Apache License 2.0 | 5 votes |
@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 #16
Source File: CacheResultInterceptor.java From java-technology-stack with MIT License | 5 votes |
@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 #17
Source File: VetTests.java From spring-init with Apache License 2.0 | 5 votes |
@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 #18
Source File: N2oSourceMergerFactory.java From n2o-framework with Apache License 2.0 | 5 votes |
@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 #19
Source File: SerializableProxyTest.java From jdal with Apache License 2.0 | 5 votes |
@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 #20
Source File: Template.java From ankush with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 #21
Source File: CookieUtils.java From training with MIT License | 4 votes |
public static String serialize(Object object) { return Base64.getUrlEncoder() .encodeToString(SerializationUtils.serialize(object)); }
Example #22
Source File: ProxySerializationTest.java From jdal with Apache License 2.0 | 4 votes |
private Object serialize(Object obj) { byte[] ser = SerializationUtils.serialize(obj); if (log.isDebugEnabled()) log.debug("Serialized [" + ser.length + "] bytes"); return SerializationUtils.deserialize(ser); }
Example #23
Source File: RestMessage.java From yes-cart with Apache License 2.0 | 4 votes |
public <T extends Serializable> T getPayloadObject() { return (T) SerializationUtils.deserialize(this.payload); }
Example #24
Source File: WsMessage.java From yes-cart with Apache License 2.0 | 4 votes |
public <T extends Serializable> T getPayloadObject() { return (T) SerializationUtils.deserialize(this.payload); }
Example #25
Source File: ProxySerializationTest.java From jdal with Apache License 2.0 | 4 votes |
@Test public void testUISerialization() { byte[] ser = SerializationUtils.serialize(testUI); TestUI deserialized = (TestUI) SerializationUtils.deserialize(ser); Assert.assertEquals(testUI.getClass(), deserialized.getClass()); }
Example #26
Source File: CookieUtils.java From training with MIT License | 4 votes |
public static <T> T deserialize(Cookie cookie, Class<T> cls) { return cls.cast(SerializationUtils.deserialize( Base64.getUrlDecoder().decode(cookie.getValue()))); }
Example #27
Source File: EventHistory.java From ankush with GNU Lesser General Public License v3.0 | 4 votes |
/** * To set the event bytes. * @param event */ @Transient public void setEvent(Event event) { setEventBytes(SerializationUtils.serialize(event)); }
Example #28
Source File: V2_33_1__Job_configuration_job_type_column_to_varchar.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void migrate( final Context context ) throws Exception { //1. Check whether migration is needed at all. Maybe it was already applied. -> Achieves that script can be // run multiple times without worries boolean continueWithMigration = false; String sql = "SELECT data_type FROM information_schema.columns " + "WHERE table_name = 'jobconfiguration' AND column_name = 'jobtype';"; try ( Statement stmt = context.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( sql ); ) { if ( rs.next() && rs.getString( "data_type" ).equals( "bytea" )) { continueWithMigration = true; } } if ( continueWithMigration ) { //2. Create a new JobType column of type VARCHAR in jobconfiguration table try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "ALTER TABLE jobconfiguration ADD COLUMN IF NOT EXISTS jobtypevarchar VARCHAR(120)" ); } //3. Move existing jobtype from bytearray column into varchar column Map<Integer, byte[]> jobTypeByteMap = new HashMap<>(); sql = "SELECT jobconfigurationid, jobtype FROM jobconfiguration WHERE jobtype IS NOT NULL"; try ( Statement stmt = context.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( sql ); ) { while ( rs.next() ) { jobTypeByteMap.put( rs.getInt( "jobconfigurationid" ), rs.getBytes( "jobtype" ) ); } } jobTypeByteMap.forEach( ( id, jobTypeByteArray ) -> { JobType jobType = (JobType) SerializationUtils.deserialize( jobTypeByteArray ); if ( jobType == null ) { log.error( "Flyway java migration error: Parsing JobType byte array failed." ); throw new FlywayException( "Parsing JobType byte array failed." ); } try ( PreparedStatement ps = context.getConnection().prepareStatement( "UPDATE jobconfiguration SET jobtypevarchar = ? WHERE jobconfigurationid = ?" ) ) { ps.setObject( 1, jobType.name() ); ps.setInt( 2, id ); ps.execute(); } catch ( SQLException e ) { log.error( "Flyway java migration error:", e ); throw new FlywayException( e ); } } ); //4. Delete old byte array column for JobType in jobconfiguration table try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "ALTER TABLE jobconfiguration DROP COLUMN jobtype" ); } //5. Rename new jobtypevarchar column to the name of the now deleted column try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "ALTER TABLE jobconfiguration RENAME COLUMN jobtypevarchar TO jobtype" ); } } }
Example #29
Source File: V2_34_5__Convert_job_configuration_binary_columns_into_varchar_data_type.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void migrateLastExecutedStatusColumn( final Context context ) throws Exception { //1. Check whether migration is needed at all. Maybe it was already applied. -> Achieves that script can be // run multiple times without worries boolean continueWithMigration = false; try ( Statement stmt = context.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( CHECK_LAST_EXECUTED_STATUS_DATA_TYPE_SQL ); ) { if ( rs.next() && rs.getString( "data_type" ).equals( "bytea" ) ) { continueWithMigration = true; } } if ( continueWithMigration ) { //2. Create a new LastExecutedStatus column of type VARCHAR in jobconfiguration table try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "ALTER TABLE jobconfiguration ADD COLUMN IF NOT EXISTS lastexecutedstatusvarchar VARCHAR(120)" ); } //3. Move existing lastexecutedstatus from bytearray column into varchar column Map<Integer, byte[]> lastExecutedStatusByteMap = new HashMap<>(); String sql = "SELECT jobconfigurationid, lastexecutedstatus FROM jobconfiguration " + "WHERE lastexecutedstatus IS NOT NULL"; try ( Statement stmt = context.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( sql ); ) { while ( rs.next() ) { lastExecutedStatusByteMap.put( rs.getInt( "jobconfigurationid" ), rs.getBytes( "lastexecutedstatus" ) ); } } lastExecutedStatusByteMap.forEach( ( id, lastExecutedStatusByteArray ) -> { JobStatus lastExecutedStatus = (JobStatus) SerializationUtils.deserialize( lastExecutedStatusByteArray ); if ( lastExecutedStatus == null ) { log.error( "Flyway java migration error: Parsing LastExecutedStatus byte array failed." ); throw new FlywayException( "Parsing LastExecutedStatus byte array failed." ); } try ( PreparedStatement ps = context.getConnection().prepareStatement( "UPDATE jobconfiguration SET lastexecutedstatusvarchar = ? WHERE jobconfigurationid = ?" ) ) { ps.setObject( 1, lastExecutedStatus.name() ); ps.setInt( 2, id ); ps.execute(); } catch ( SQLException e ) { log.error( "Flyway java migration error:", e ); throw new FlywayException( e ); } } ); //4. Delete old byte array column for LastExecutedStatus in jobconfiguration table try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "ALTER TABLE jobconfiguration DROP COLUMN lastexecutedstatus" ); } //5. Rename new lastexecutedstatusvarchar column to the name of the now deleted column try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "ALTER TABLE jobconfiguration RENAME COLUMN lastexecutedstatusvarchar TO lastexecutedstatus" ); } //6. Set default values where NULL is present try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "UPDATE jobconfiguration SET lastexecutedstatus = 'NOT_STARTED' WHERE lastexecutedstatus IS NULL" ); } } }
Example #30
Source File: V2_34_5__Convert_job_configuration_binary_columns_into_varchar_data_type.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void migrateJobStatusColumn( final Context context ) throws Exception { //1. Check whether migration is needed at all. Maybe it was already applied. -> Achieves that script can be // run multiple times without worries boolean continueWithMigration = false; try ( Statement stmt = context.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( CHECK_JOB_STATUS_DATA_TYPE_SQL ); ) { if ( rs.next() && rs.getString( "data_type" ).equals( "bytea" )) { continueWithMigration = true; } } if ( continueWithMigration ) { //2. Create a new JobStatus column of type VARCHAR in jobconfiguration table try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "ALTER TABLE jobconfiguration ADD COLUMN IF NOT EXISTS jobstatusvarchar VARCHAR(120)" ); } //3. Move existing jobstatus from bytearray column into varchar column Map<Integer, byte[]> jobStatusByteMap = new HashMap<>(); String sql = "SELECT jobconfigurationid, jobstatus FROM jobconfiguration WHERE jobstatus IS NOT NULL"; try ( Statement stmt = context.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( sql ); ) { while ( rs.next() ) { jobStatusByteMap.put( rs.getInt( "jobconfigurationid" ), rs.getBytes( "jobstatus" ) ); } } jobStatusByteMap.forEach( ( id, jobStatusByteArray ) -> { JobStatus jobStatus = (JobStatus) SerializationUtils.deserialize( jobStatusByteArray ); if ( jobStatus == null ) { log.error( "Flyway java migration error: Parsing JobStatus byte array failed." ); throw new FlywayException( "Parsing JobStatus byte array failed." ); } try ( PreparedStatement ps = context.getConnection().prepareStatement( "UPDATE jobconfiguration SET jobstatusvarchar = ? WHERE jobconfigurationid = ?" ) ) { ps.setObject( 1, jobStatus.name() ); ps.setInt( 2, id ); ps.execute(); } catch ( SQLException e ) { log.error( "Flyway java migration error:", e ); throw new FlywayException( e ); } } ); //4. Delete old byte array column for JobStatus in jobconfiguration table try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "ALTER TABLE jobconfiguration DROP COLUMN jobstatus" ); } //5. Rename new jobstatusvarchar column to the name of the now deleted column try ( Statement stmt = context.getConnection().createStatement() ) { stmt.executeUpdate( "ALTER TABLE jobconfiguration RENAME COLUMN jobstatusvarchar TO jobstatus" ); } } }