JsonField<T> class abstract

An abstract base class for all JSON field types.

JsonField provides the foundational structure for handling individual fields within JSON-serializable models. It manages field metadata, validation messages (errors, warnings, information), and value storage with type safety.

Key Features:

  • Type-safe value storage with generic type parameter T
  • Validation message management (errors, warnings, information)
  • Null-safety with separate rawValue and typed value access
  • Equality comparison based on field name and value

Type Parameter:

  • T: The type of value this field holds (e.g., String, int, DateTime).

Subclassing: Subclasses should override the value getter and setter to provide type-specific behavior, such as parsing strings, providing default values, or converting types.

Usage Example:

class JsonString extends JsonField<String> {
  JsonString(super.fieldName);
  @override
  String get value => rawValue ?? "";
}

See also:

Implementers

Constructors

JsonField(String fieldName)
Creates a new JsonField instance with the specified field name.

Properties

error String?
An error message associated with this field, if any.
getter/setter pair
fieldName String
The name of this field as it appears in JSON data.
final
hasError bool
Returns true if this field has an error message.
no setter
hashCode int
Returns the hash code for this field.
no setteroverride
hasInformation bool
Returns true if this field has an informational message.
no setter
hasWarning bool
Returns true if this field has a warning message.
no setter
information String?
An informational message associated with this field, if any.
getter/setter pair
isNotNull bool
Returns true if the raw value of this field is not null.
no setter
isNull bool
Returns true if the raw value of this field is null.
no setter
rawValue ↔ T?
The raw, unprocessed value stored in this field.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value ↔ T
Returns the typed value of this field.
getter/setter pair
warning String?
A warning message associated with this field, if any.
getter/setter pair

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() → dynamic
Serializes the field value to JSON format.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
Determines whether this field is equal to another object.
override