Skip to content

Commit

Permalink
fix: Null value throwing type error
Browse files Browse the repository at this point in the history
  • Loading branch information
Unnoen committed Oct 15, 2023
1 parent b22842c commit 2554348
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packageManager": "yarn@3.6.4",
"name": "@unnoen/untypedjson",
"description": "A simple JSON deserializer and serializer for Node.js and the browser using TypeScript decorators.",
"version": "1.2.1",
"version": "1.2.2",
"type": "module",
"license": "MIT",
"author": "Unnoen",
Expand Down
6 changes: 3 additions & 3 deletions src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const verifyType = (propertyKey: string, properties: IJsonPropertyMetadata, json
type,
} = properties;

if (typeof json[jsonProperty] === 'undefined' && nullabilityMode === (PropertyNullability.IGNORE || PropertyNullability.PASS)) {
if ((typeof json[jsonProperty] === 'undefined' || json[jsonProperty] === null) && nullabilityMode === (PropertyNullability.IGNORE || PropertyNullability.PASS)) {
return;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ const verifyType = (propertyKey: string, properties: IJsonPropertyMetadata, json
* @param {boolean} serialize Whether to serialize or deserialize.
* @returns {void}
*/
const mapObjectProperty = (propertyKey: string, properties: IJsonPropertyMetadata, fromObject: any, toObject: any, serialize = false): void => {
const mapObjectProperty = (propertyKey: string, properties: IJsonPropertyMetadata, fromObject: any, toObject: any, serialize: boolean = false): void => {
const {
jsonProperty,
array,
Expand Down Expand Up @@ -216,7 +216,7 @@ export const DeserializeObject = <T>(json: object | string, classReference: new(
* @returns {object} The serialized JSON object.
*/
export const SerializeObject = <T>(instance: T): object => {
const json: any = {};
const json: object = {};

let classConstructor = instance.constructor;

Expand Down
2 changes: 1 addition & 1 deletion test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ describe('JsonProperty Nullability Tests', () => {
expect(() => {
return DeserializeObject({
int: 1,
test: 'test',
test: null,
}, TestClass);
}).not.toThrow();
});
Expand Down

0 comments on commit 2554348

Please sign in to comment.