serialize
serialize copied to clipboard
Nulls serialization
Primitives with null values are not presented in serialized object
@Model()
class User {
@Field()
firstName: string;
@Field()
lastName: string;
}
let admin = new User();
admin.firstName = "Anton";
admin.lastName = null;
console.log(serialize(admin));
// {firstName: "Anton"}
// but expected
// {firstName: "Anton", lastName: null}
Question is here https://github.com/AndreyZelenskiy/serialize/blob/master/src/serializers/field.utils.ts
export function isPresent(obj: Object): boolean {
return obj !== undefined && obj !== null;
}
Perhaps remove obj !== null
?