Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.6
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
One fairly common problem case is that of bi-directional linking between objects; most commonly with parent/child relationships.
By default these can lead to infinite recursion (due to cyclic reference). But for simple parent/child style relationships, it seems possible to find a way to handle linkage gracefully.
It might be possible to annotate one or both links in a way that allows suppression of serialization for one link (usually the "parent" link), and then recreating the linkage on deserialization. Currently this can only be done by modifying value classes to do this. This is fairly simple thing to do, but requires ability to modify code, and also adds serialization-specific code in otherwise regular POJOs. As such, annotation-based solution would be beneficial.
I think I know a reasonable way to indicate relationship:
Limitation in usage is that relationship between the two must be possible only using declared type (in future, could maybe allow a discriminator too – for now, let's assume simple case).
If so, parent type deserializer can do post-processing step after instantiating children: it needs to inform child deserializer that parent reference is now available, to request assignment
This should allow re-creating back references fairly easily, reliably and efficiently. The only question is when there's time to do it.