Both fiction and (contemporary at the time) conspiracy theories have many examples of "The king chooses to place a worthy replacement on the throne instead of his own not-qualified-to-rule offspring; with said impostor being presented to the populace as an actual heir by blood" trope.
Were there any actual historical events that fit that pattern? If there were many, who was the latest known?
Just to be clear, I'm interested in cases where (almost) everyone was told that the "heir" was indeed a child of the monarch, at the monarch's wish, and replacing an actual child (independently of said child surviving).
This does not include an usurper (like LzheDmitry I) who claimed blood relation to the previous king without being acknowledged by that monarch himself.