Hypothetical scenario: output stream of objects of type Message that implement Serializable. Message has members Header and Body. Header is small and Body can be large. Say I want to write a filter based on info in the Header: is there a way to do it without having to deserialize Body?
You shall NOT serialize Body in the first place by declaring it transient.
But if you already have serialized the Message object, there is no way to selectively deserialize specific members.
You just discovered one of the weaknesses of object-oriented programming compared to databases: "What if I just want half of a Customer object?"
What I would say is that you need to split your Message class into something like MessageHeader, with the header information and no reference to the body, and a MessageBody class that has the body and a key that can be used to look up the header data. Then you need to store and retrieve the serialized MessageHeader and MessageBody objects separately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With