readFromMap method

  1. @override
void readFromMap(
  1. Map<String, dynamic> object
)
override

Reads values from object.

Use read instead of this method. read applies filters to object before calling this method.

This method is used by implementors to assign and use values from object for its own purposes. SerializableExceptions should be thrown when object violates a constraint of the receiver.

Implementation

@override
void readFromMap(Map<String, dynamic> object) {
  object.forEach((key, v) {
    final property = responseKeyProperties[key];
    if (property == null) {
      throw ValidationException(["invalid input key '$key'"]);
    }
    if (property.isPrivate) {
      throw ValidationException(["invalid input key '$key'"]);
    }

    if (property is ManagedAttributeDescription) {
      if (!property.isTransient) {
        backing.setValueForProperty(
          property,
          property.convertFromPrimitiveValue(v),
        );
      } else {
        if (!property.transientStatus!.isAvailableAsInput) {
          throw ValidationException(["invalid input key '$key'"]);
        }

        final decodedValue = property.convertFromPrimitiveValue(v);

        if (!property.isAssignableWith(decodedValue)) {
          throw ValidationException(["invalid input type for key '$key'"]);
        }

        entity.runtime
            .setTransientValueForKey(this, property.name, decodedValue);
      }
    } else {
      backing.setValueForProperty(
        property,
        property.convertFromPrimitiveValue(v),
      );
    }
  });
}