Skip to content

Serialize & Deserialize when the class attribute is null #25

@tomas-ortega

Description

@tomas-ortega

When you have a class with a null vale in some attribute, custom property name in serialization and deserialization processs not work, and json property name is ignored.

Examples are in TypeScript Syntax

Ex. User Domain Class
export class User {

@JsonProperty({name: "id"})
public _id: number;

@JsonProperty({name: "name"})
public _name: string;

@JsonIgnore()
public _password: string;

public constructor() {
    this._id = null;
    this._name = "Test User Name";
    this._password = "gsa@aglaX!";
}

}

Ex. Serialization
let userInstance: User;
userInstance = ObjectMapper.serialize(singleTestDTO);

User instance: {"_id": null, "name": "Test User Name"}

If don't explicitly initialize _id to null, works, or if initialize to undefined, but no with null value...

It would be wonderful it worked with null values

Congratulations on working with module! 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions