Copied serialization classes from paymentlib.