json_serializable_uuid_converter 1.0.0
json_serializable_uuid_converter: ^1.0.0 copied to clipboard
JsonConverter for UUIDs
A JsonConverter
to serialize and deserialize UuidValue
objects.
Features #
- Easy to use, just add
UuidValueConverter()
in your@JsonSerializable(converters: [])
annotation - Minimal dependencies: compatible with every version of
package:uuid/uuid.dart
from v4 onwards. - Full test coverage
Getting started #
Install the library from pub.dev
$ flutter pub add json_serializable_uuid_converter
copied to clipboard
Usage #
import 'package:json_serializable_uuid_converter/json_serializable_uuid_converter.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:uuid/uuid.dart';
@JsonSerializable(converters: [UuidValueConverter(validate: true), UuidValueConverter.nullable(validate: false)])
class MyModel {
final UuidValue requiredId;
final UuidValue? optionalId;
const MyModel({
required this.requiredId,
this.optionalId,
});
factory MyModel.fromJson(Map<String, dynamic> json) => _$MyModelFromJson(json);
Map<String, dynamic> toJson() => _$MyModelToJson(this);
}
copied to clipboard
Other packages #
If you need ready-made JsonSerializable
converters for other common types, take a look at these packages: