JsonModel class abstract

An abstract base class for all JSON-serializable models in the application.

JsonModel provides a comprehensive framework for handling JSON serialization and deserialization, field management, and validation messaging. It serves as the foundation for all data models that need to interact with JSON data.

Key Features:

  • Automatic JSON serialization/deserialization through fromJson and toJson
  • Field-level and general error/warning/information message management
  • Type-safe field access using the [] and []= operators
  • Automatic handling of field validation messages from server responses

Usage:

class UserModel extends JsonModel {
  @override
  List<JsonField> get fields => [
    JsonString('name'),
    JsonInteger('age'),
    JsonDate('createdAt'),
  ];
}

See also:

Mixed-in types
Implementers

Constructors

JsonModel()

Properties

error String?
Returns the first general error message, or null if there are no errors.
no setter
errors Map<String, String?>
A map of field-specific error messages, keyed by field name.
getter/setter pair
fields List<JsonField>
The list of JSON fields that define the structure of this model.
no setter
generalErrors List<String>
A list of general error messages that apply to the entire model.
getter/setter pair
generalInformations List<String>
A list of general informational messages about the model.
getter/setter pair
generalWarnings List<String>
A list of general warning messages that apply to the entire model.
getter/setter pair
hasError bool
Returns true if the model has any field-specific or general errors.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasInformation bool
Returns true if the model has any field-specific or general informational messages.
no setter
hasWarning bool
Returns true if the model has any field-specific or general warnings.
no setter
information String?
Returns the first general informational message, or null if there are none.
no setter
informations Map<String, String?>
A map of field-specific informational messages, keyed by field name.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
warning String?
Returns the first general warning message, or null if there are no warnings.
no setter
warnings Map<String, String?>
A map of field-specific warning messages, keyed by field name.
getter/setter pair

Methods

fromJson(dynamic json) → void
Deserializes JSON data into this model instance.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Serializes this model instance to a JSON map.
override
toString() String
Returns a JSON string representation of this model.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String name) → dynamic
Retrieves the value of a field by its name using bracket notation.
operator []=(String name, dynamic value) → void
Sets the value of a field by its name using bracket notation.