Fix serialization of Defined/Nullable

Without this only user data types will work, and Int/Double only incidentally work. Added a couple test-cases too.