serialize according to discriminator