I have a problem with Java serialization. I have a graph of objects and you want to configure where to stop when I serialize the root object from client to server.
Let me make this a little concrete, understandable, by providing a sample script. I have classes like
Company Employee (abstract)
Manager expands staff
Secretary expands staff
Analyst expands project staff
Here are the ratios:
Company (1) --- (p) Employee
Manager (1) --- (p) Project
Analyst (1) --- (p) Project
Imagine, I am on the client side, and I want to create a new company, assign it to 10 employees (new or some existing) and send this new company to the server. What I expect in this scenario is to serialize the company and all the bounding employees on the server side, because I will save the relationships in the database. There is still no problem, because the Java serialization engine by default serializes the entire graph of an object, excluding a field that is static or temporary.
My goal is the following scenario. Imagine, I downloaded the company and its 1000 employees from the server to the client side. Now I only want to rename the company name (or another field that directly belongs to the company) and update this record. This time I want to send only the company’s object to the server side, and not the entire list of employees (I just update the name, the employees are irrelevant in this case). My goal also includes the configuration of the utterance, the transfer of the company AND employees, not Project-Relations, you should stay there.
Do you know any possibility of achieving this in a general way without implementing writeObject, readObject for each Entity-Object? What will be your suggestions?
I would really appreciate your answers. I am open to any ideas and ready to answer your questions if something is unclear.
source share