Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize a null value in a list #25

Open
reservoir-dogs opened this issue Jan 5, 2019 · 0 comments
Open

Deserialize a null value in a list #25

reservoir-dogs opened this issue Jan 5, 2019 · 0 comments

Comments

@reservoir-dogs
Copy link

Great library!

If I deserialize an array with a null value, I have an error

Uncaught TypeError: Cannot read property 'id' of null
    at eval (deserialize.js:32)

Could you check value before deserialize it ?

Maybe like this

function deserializeObject(object, definition, options) {
	var primitive = definition.type === String || definition.type === Boolean || definition.type === Number;
	var value = object;

	if(value != null)
	{
		var converter = definition.converter || propertyConverters.get(definition.type);
		if (converter) {
			return converter.deserialize(value);
		}
		if (!primitive) {
			var objDefinition = objectDefinitions.get(definition.type);
			if (objDefinition) {
				return deserialize(value, definition.type);
			}
		}
	}

	return value;
}

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant