Use template to serialize QVariantHash and QVariantMap

Use template to serialize QVariantHash and QVariantMap, So the code looks cleaner. 

BTW: I suggest expanding tab to spaces, the code otherwise looks strange in editors with different tab setting.