This new approach uses a static method which takes the object as
a argument. This has the advantage that its constness can be a
template parameter, allowing a single implementation that sees the
object as const for serialization and non-const for deserialization,
without casts.More boilerplate is included in the new macro as well.
This is a backport of Core PR17850 [1/2]
Commit https://github.com/bitcoin/bitcoin/pull/17850/commits/ca33451535dc29f64d37c49af8b22142d7716d0d