Method for validation of Serializable Objects
Method for validation of Serializable Objects
This commit is contained in:
parent
e2f8cdd817
commit
e0ca514118
|
@ -25,5 +25,9 @@ public class SerializationUtils {
|
|||
Object o = ois.readObject();
|
||||
return cl.cast(o);
|
||||
}
|
||||
|
||||
public static boolean isSerializable(Class<?> it) {
|
||||
return it.isPrimitive() || it.isInterface() || Serializable.class.isAssignableFrom(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.baeldung.serialization;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -76,4 +77,11 @@ public class SerializationUnitTest {
|
|||
assertTrue(p2.getAge() == p.getAge());
|
||||
assertTrue(p2.getName().equals(p.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSerializingUsingCustomSerializationUtils_ThanOk(){
|
||||
assertFalse(com.baeldung.util.SerializationUtils.isSerializable(Address.class));
|
||||
assertTrue(com.baeldung.util.SerializationUtils.isSerializable(Person.class));
|
||||
assertTrue(com.baeldung.util.SerializationUtils.isSerializable(Integer.class));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue