SCJP1.4(96%)<br />A drop of ink can make millions think.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
SCJP1.4(96%)<br />A drop of ink can make millions think.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
It has been done... it's called "serialization" The thing is that you cannot in general do this blindly; for example, some of the state may refer to resources such as sockets or files that cannot be externalised. That is where infrastructure such as Serializable, Externalizable and "transient" comes in.Originally posted by Rovas Kram:
You can use classes like java.lang.reflect.Field to recursively get the primative fields from the class object and save those. This could be written so that it works with any class object - might have already been done.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Originally posted by Peter den Haan:
Is it a JavaBean (or JavaBean object graph)? What about XML serialization - i.e. java.beans.XML(En|De)coder?
- Peter
42
Ok. Let me rephrase that.Originally posted by Jeroen Wenting:
Is it a JavaBean (or JavaBean object graph)? What about XML serialization - i.e. java.beans.XML(En|De)coder?
if it were a proper bean it would implement Serializable which is a requirement according to the Java Beans API.
You're right, it's so much better now that we've cleared that up.Is it a Java class with a zero-argument constructor and property accessors following the JavaBean method naming patterns, or with an associated BeanInfo object facilitating access to the properties, but not necessarily Serializable or Externalizable and therefore not necessarily formally a JavaBean[tm]; or an object graph of Java classes with zero-argument constructors and property accessors following the JavaBean method naming patterns, or with BeanInfo objects, but not necessarily Serializable or Externalizable and therefore not necessarily formally an object graph of JavaBean[tm]s? What about XML serialization - i.e. java.beans.XML(En|De)coder?
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
It has been done... it's called "serialization" The thing is that you cannot in general do this blindly; for example, some of the state may refer to resources such as sockets or files that cannot be externalised. That is where infrastructure such as Serializable, Externalizable and "transient" comes in.
Why not? As long as the public property accessors are sufficient to save and restore the bean's state - and do return either primitives or objects that can be persisted in the same way - things are fine. And even where this is not the case all is not lost: you can provide your own PersistenceDelegate for a bean to customise XML persistence.Originally posted by Rovas Kram:
She can't use XMLEncoder if here class does not implement Serializable [...]
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Why not? As long as the public property accessors are sufficient to save and restore the bean's state
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |