JsonParam class

Ensure that serializable parameters can be successfully serialized to Json.

When used with freezed, the values generated by freezed may not be converted to json.

Using @JsonSerializable(explicitToJson: true) will grant toJson, but it may not work because it is done for all parameters. Therefore, please use this annotation as it will be assigned to a specific parameter.

If you want to specify the name of the key when Jsonized, specify name.

Jsonにシリアライズ可能なパラメーターを正常にシリアライズできるようにします。

freezedで利用する場合、freezedで生成される値がjsonに変換できない場合があります。

@JsonSerializable(explicitToJson: true)を利用するとtoJsonが付与されますが、すべてのパラメーターに対して行われるのでうまく行かない場合があります。 そのためこのアノテーションを特定のパラメーターに付与されるためこのアノテーションを利用してください。

Json化した場合のキーの名前を指定したい場合はnameを指定します。

@freezed
@formValue
@immutable
@CollectionModelPath("shop")
class ShopModel with _$ShopModel {
  const factory ShopModel({
    @Default("") String name,
    @Default("") String description,
    @jsonParam OtherValue? other,
  }) = _ShopModel;
  const ShopModel._();

  factory ShopModel.fromJson(Map<String, Object?> json) => _$ShopModelFromJson(json);

  static const document = _$ShopModelDocumentQuery();

  static const collection = _$ShopModelCollectionQuery();
}
Available Extensions

Constructors

JsonParam({String? name})
Ensure that serializable parameters can be successfully serialized to Json.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
name String?
Specify the name of the key when Jsonized.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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