I think you need to use DataTypes.toStream and DataTypes.fromStream in order to also correctly serialize ArrayType and SetType.  That way TYPE_REGISTRY can probably stay private