Skip to content

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

Description

@ewrayjohnson

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions