loopback-datasource-juggler
loopback-datasource-juggler copied to clipboard
null value not persisted for properties of type JSON, Any, or Object
Steps to reproduce
- Create a model with a property of either of the following types: JSON, Any, or Object
- Ensure the property above is not required.
- Create an instance of the above model setting the property value to null
- Query the model where the value of the property is null and see that the created instance is not returned
Current Behavior
'null' is stored in the dataSource
Expected Behavior
null is stored in the dataSource
Proposed fix
Replace this:
if (type === 'JSON' || type === 'Any' || type === 'Object' || data[propName] instanceof Array) {
res[propName] = JSON.stringify(data[propName]);
} else {
res[propName] = data[propName];
}
With this:
const value = data[propName];
if (value !== null && (type === 'JSON' || type === 'Any' ||
type === 'Object' || value instanceof Array)) {
res[propName] = JSON.stringify(value);
} else {
res[propName] = value;
}
Additional information
win32 x64 12.18.3 "loopback": "^3.28.0", "loopback-datasource-juggler": "^3.28.0",
Related Issues
Could not find a related issue
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.