Closed mikedavison closed 4 years ago
Ok so I have a handle on how the application works and figured out how to do what I need in a round about way. Lengthy description to help others.
in a nutshell there seems no way to set the parent
because the class object is only created after all of the data required is read from the deserializer. In the example above assuming no serializewhen , the sequence is:
intOfA
intOfB
B
objectintOfB
into class B object B
intOfA
value and object B
So, this means that I cannot set parent
field in B
until after A
has been created right at the end and this cannot be done in the confines of the serializer.
How did I get around my problem. I worked around some of the issues by using the serializer context feature. I still had to go over the objects and set parent references post deserialization.
Is intOfA something that is contained in the data source? If not, then the only way to do this is to pass in a serialization context that specifies intOfA for a given deserialization operation.
I previously raised this in a complex way (see #88) but would like a more succinct answer. Pseudo Code:
As i understand your code during deserialization , it would construct A, read "
intOfA
", then construct B and conditionally read "intOfB
. My questions are:parent
field prior to deserializing B? Normally I would set this by calling the class constructor (public B(A parent) { this.parent = parent}
)intOfA
to test whether to deserializeintOfB
?