TreeNodeDto

@Serializable
data class TreeNodeDto<T>(val value: T, val children: List<TreeNodeDto<T>> = emptyList())(source)

A serializable, acyclic view of a TreeNode subtree. TreeNode itself holds a back-reference to its parent (a cycle), so it cannot be @Serializable directly — convert to/from this DTO instead.

val json = Json.encodeToString(tree.toDto())
val restored = Json.decodeFromString<TreeNodeDto<String>>(json).toTreeNode()

Constructors

Link copied to clipboard
constructor(value: T, children: List<TreeNodeDto<T>> = emptyList())

Properties

Link copied to clipboard
Link copied to clipboard
val value: T

Functions

Link copied to clipboard

Rebuilds a mutable TreeNode tree from this DTO.