loopback-datasource-juggler icon indicating copy to clipboard operation
loopback-datasource-juggler copied to clipboard

null value not persisted for properties of type JSON, Any, or Object

Open ewrayjohnson opened this issue 3 years ago • 2 comments

Steps to reproduce

  1. Create a model with a property of either of the following types: JSON, Any, or Object
  2. Ensure the property above is not required.
  3. Create an instance of the above model setting the property value to null
  4. 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

ewrayjohnson avatar Jul 12 '21 11:07 ewrayjohnson

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.

stale[bot] avatar Sep 10 '21 13:09 stale[bot]

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.

stale[bot] avatar Nov 09 '21 15:11 stale[bot]