1
Vote

JSON payload values missing when set to 0 or empty string

description

When attempting to create a new entity with a value of 0 or empty string in JSON, the value is never rendered in the payload. It is relying on the data service implementation to assume that the default value will be used if not included (zero for numeric, empty string for non-nullable properties and null for nullable properties).
 
SaveResult->CreateChangeSetBodyForResourceInJSON is incorrectly suppressing any property values that are set to 0 or empty string regardless of the property's type or whether it supports nulls or not.
 
For example:
If an entity key is defined as:
/**
 * EntityProperty
 * NotNullable
 * Edm.Int32
 */
public $primaryKey;
 
 
And is set to zero:
$e = MyEntity::CreateMyEntity(0);
$proxy->AddToMyEntity($e);
$proxy->SaveChanges();
 
The resulting JSON output will not have the primaryKey data included.
 
To fix the problem, one can simply remove the following code from the CreateChangeSetBodyForResourceInJSON method:
if ($prop->getValue($object) == '')
{
continue;
}

comments