Es totalmente factible, siempre y cuando todas las propiedades de tu clase también sean Serializables.
http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html
"Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable."
Hola a todos:
Mi cuestión es si se puede enviar una clase de forma serializada. Es decir, mi código es el siguiente:
try {
Alumno alumno_aux=new Alumno("Juan","Pérez",33);
FileOutputStream fos=new FileOutputStream("c:\\fich_lsg.txt");
ObjectOutputStream sos = new ObjectOutputStream(fos);
sos.writeObject(alumno_aux);
sos.close();
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
Pero me da error. Hasta ahora había mandado cosas serializadas muy sencillas como String, Date, etcétera, pero nunca una clase entera.
¿Es posible esto? ¿Cuál es el fallo del código?
Gracias