json_serializable_uuid_converter 1.0.0 copy "json_serializable_uuid_converter: ^1.0.0" to clipboard
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:

0
likes
130
points
71
downloads

Publisher

verified publisherdogeek.me

Weekly Downloads

2024.09.27 - 2025.04.11

JsonConverter for UUIDs

Repository (GitHub)
View/report issues

Topics

#json-serializable #uuid #codegen #converter

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

json_annotation, uuid

More

Packages that depend on json_serializable_uuid_converter