JsonKey class

Customizes JSON serialization for a specific field.

@Model(fromJson: true, toJson: true)
class User {
  @JsonKey(name: 'user_id')
  final int id;

  @JsonKey(ignore: true)
  final String cache;

  @JsonKey(defaultValue: '0')
  final int count;
}

Constructors

JsonKey({String? name, String? fromJson, String? toJson, String? defaultValue, bool ignore = false, bool includeIfNull = true, bool ignoreIfNull = false, NamingConvention? convention})
const

Properties

convention → NamingConvention?
Field-level naming convention override
final
defaultValue → String?
Default value expression (as string)
final
fromJson → String?
Custom fromJson function name
final
hashCode → int
The hash code for this object.
no setterinherited
ignore → bool
Skip this field during serialization
final
ignoreIfNull → bool
Skip this field if null (inverse of includeIfNull)
final
includeIfNull → bool
Include field in JSON even when null (defaults to true)
final
name → String?
Custom JSON key name
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
toJson → String?
Custom toJson function name
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited