json_factory_annotation 1.0.2 copy "json_factory_annotation: ^1.0.2" to clipboard
json_factory_annotation: ^1.0.2 copied to clipboard

Annotation for centralized, type-safe JSON factory generation in Dart models. Supports generic API responses and complex object graphs.

example/lib/example.dart

import 'package:json_factory_annotation/json_factory_annotation.dart';

// Example of using @JsonModel annotation with manual JSON serialization
@JsonModel()
class User {
  final int id;
  final String name;
  final String email;

  User({
    required this.id,
    required this.name,
    required this.email,
  });

  factory User.fromJson(Map<String, dynamic> json) => User(
        id: json['id'] as int,
        name: json['name'] as String,
        email: json['email'] as String,
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'name': name,
        'email': email,
      };
}

void main() {
  // Example JSON data
  final userJson = {
    'id': 1,
    'name': 'John Doe',
    'email': 'john@example.com',
  };

  // Creating object from JSON
  final user = User.fromJson(userJson);

  // Converting object back to JSON
  print('User JSON: ${user.toJson()}');
  // Output: User JSON: {id: 1, name: John Doe, email: john@example.com}
}
0
likes
160
points
73
downloads

Publisher

unverified uploader

Weekly Downloads

Annotation for centralized, type-safe JSON factory generation in Dart models. Supports generic API responses and complex object graphs.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on json_factory_annotation