setPropertyFromObjectIfNotDefault method

void setPropertyFromObjectIfNotDefault(
  1. String property,
  2. ISerialisable defaultValue,
  3. ISerialisable? value
)

Set property from serialisable of value is not equal to the default value.

  • This is useful for preventing default state from bloating saved JSON models.
  • Object must implement == as value equality .

Implementation

void setPropertyFromObjectIfNotDefault(String property, ISerialisable defaultValue, ISerialisable? value)
{
  if (value != null &&
      value != defaultValue) {
    setPropertyUnsafe(property, new MarshalledObject.marshal(value).getRawValue() );
  }
  else {
    removeProperty(property);
  }
}