For this specific project I need to serialize my entity layer (made of POJO’s) to files. As I have the need for updating specific objects I would like to use one file per serialized object.
Example: Customer –ArrayList-> Order –ArrayList-> Product
When I edit a customer, and then serialize it using the java.io.Serializable interface, all fields, and their fields (please correct me if wrong), get serialized.
How would I apply serialization in such a way that only one object per file is used? I already have given each object a uniqe UUID which is used as filename when serializing.
If there are any frameworks that do File based ORM, that would be even better 😉
I’m not familiar with such framework.
What you can do is use other frameworks such as apache BeanUtils in order to perform the following recursive algorithm:
A. For each object gets its properties (assuming the object is a Java bean).
B. For each primitive field , write all primitives to file (you can use reflection to determine if a field is primitive or not).
C. For each non primitive file, write a special section in the file, pointing to the file name that will contain the object that is the value of the field.
D. Call recursively the algorithm for each non primitive field.
Similar approach can be done for collections –
HashMap, ArrayList and others.
The serializing code for the primitive elements can be the code provided by @Anshu