|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.common.testing.SerializableTester
@Beta public final class SerializableTester
Helper class for testing whether a class is serializable.
Unlike com.google.common.util.SerializationChecker
, this class
tests not only whether serialization succeeds, but also whether the
serialized form is correct: i.e., whether an equivalent object can be
reconstructed by deserializing the serialized form.
If serialization fails, you can use SerializationChecker
to
diagnose which referenced fields were not serializable.
Method Summary | ||
---|---|---|
static
|
reserialize(T object)
Serializes and deserializes the specified object. |
|
static
|
reserializeAndAssert(T object)
Serializes and deserializes the specified object and verifies that the re-serialized object is equal to the provided object, that the hashcodes are identical, and that the class of the re-serialized object is identical to that of the original. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> T reserialize(T object)
Note that the specified object may not be known by the compiler to be a
Serializable
instance, and is thus declared an
Object
. For example, it might be declared as a List
.
RuntimeException
- if the specified object was not successfully
serialized or deserializedpublic static <T> T reserializeAndAssert(T object)
Note that the specified object may not be known by the compiler to be a
Serializable
instance, and is thus declared an
Object
. For example, it might be declared as a List
.
Note also that serialization is not in general required to return an
object that is equal to the original, nor is it
required to return even an object of the same class. For example, if
sublists of MyList
instances were serializable, those sublists
might implement a private MySubList
type but serialize as a plain
MyList
to save space. So long as MyList
has all the public
supertypes of MySubList
, this is safe. For these cases, for which
reserializeAndAssert
is too strict, use reserialize(T)
.
RuntimeException
- if the specified object was not successfully
serialized or deserialized
GuavaAsserts.TestAssertionFailure
- if the re-serialized object is
not equal to the original object, or if the hashcodes are different.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |