There’s space for optimization.
The serializer mantains the inheritance relation graph between the registered classes.
The castSequence performs BFS between the given pair of registered types. I expected it to be fast (the inheritance hierarchies aren’t that big) but it apparently isn’t.