Possible Duplicate:
Converting any object to a byte array in java
I have a class that needs to be cached. The cache API provides an interface that caches byte[]. My class contains a field as List<Author>, where Author is another class. What is the correct way for me to turn List<Author> to byte[] for caching? And retrieve the byte[] from cache to reconstruct the List<Author>?
More detail about Author class: it is very simple, only has two String fields. One String field is possible to be null.
Author class should implement
SerializableThen you can use
ObjectOutputStreamto serialize the object andByteArrayOutputStreamto get it written as bytes.Then deserialize it using ObjectInputStream and convert back.