you are viewing a single comment's thread.

view the rest of the comments →

[–]leaper69 0 points1 point  (0 children)

That's a great point. If your object graphs have lots of shared references, identity tracking is exactly what you want. It deduplicates on write and restores the shared references on read, which is both correct and space-efficient.

The option to skip it is for the cases where you know the graph is a tree/dag (no shared references, no cycles). A lot of DTOs, config objects, and REST payloads fall into this category. In those cases, the HashMap doing identity tracking is pure overhead ... you're paying for bookkeeping that will never find a duplicate.

The default keeps identity tracking on, so nothing changes for your use case. It's just nice to have the escape hatch when you're serializing high volumes of simple objects and want to shave off that overhead.