freezer 0.0.2 copy "freezer: ^0.0.2" to clipboard
freezer: ^0.0.2 copied to clipboard

Automatically generates object classes supported by the freezed library directly from JSON files.

freezer

The Most Powerful Way to Automatically Generate Model Objects from JSON Files ⚡


GitHub Sponsor GitHub Sponsor

pub package Dart SDK Version Test Analyzer Issues Pull Requests Stars Contributors Code size Last Commits License Contributor Covenant


1. Guide 🌎 #

This library was built on the foundation of the json_serializable and freezed libraries.

This library provides the ability to automatically generate class objects supported by the freezed library directly from JSON files.

Show some ❤️ and star the repo to support the project.

Note
Many of the specifications in this library are still in development. Your contributions are very welcome!

1.1. Motivation 💎 #

  • Realize JSON-based model design.
  • Realize automatic generation of model objects from design.
  • Synchronize the design and implementation of model objects.
  • Expand the possibilities of the freezed library even more.
  • etc...

1.2. Getting Started 🏄 #

1.2.1. Prerequisite #

The codes automatically generated by this library depend on json_serializable and freezed.

So, let's add the prerequisite libraries to pubspec.yaml as follows.

dependencies:
  json_annotation: latest
  freezed_annotation: latest

dev_dependencies:
  json_serializable: latest
  freezed: latest

1.2.2. Install Library #

Next, let's install the libraries to use the freezer functionality.

With Dart:

dart pub add freezer

With Flutter:

flutter pub add freezer

1.2.3. Create a JSON File #

freezer interprets JSON files as design information and automatically generates object classes supported by the freezed library.

And you need to note following rules when you use the freezer.

  1. freezer parses files with the .freezer.json extension.
  2. freezer parses JSON files stored in the .design folder.

So, now let's create a JSON file with the following structure as a trial.

{
  "shop": {
    "name.!required": "My Fancy Shop",
    "product.!as:products": [
      {
        "name": "Chocolate",
        "price": 5.99,
        "product_type": 1
      },
      {
        "name": "Gummy",
        "price": 8.99
      }
    ],
    "closed": false
  }
}

And then store this JSON file in the .design folder of the root of project.

.
├── analysis_options.yaml
├── design
│   └── sample
│       └── shop.freezer.json
├── lib
├── pubspec.lock
└── pubspec.yaml

1.2.4. Execute Command #

Now let's execute the following command and see what happens!

dart pub run freezer:main

Then, this trial is successful if the following output is obtained.

Started process for 1 files

[INFO] Reading cached asset graph completed, took 28ms
[INFO] Checking for updates since last build completed, took 297ms
[INFO] Running build completed, took 4.0s
[INFO] Caching finalized dependency graph completed, took 19ms
[INFO] Succeeded after 4.1s with 0 outputs (3 actions)

┏━━ Generated dart files
┃  ┣━━ 🎉 /Users/user/freezer/lib/sample/products.dart
┃  ┣━━ 🎉 /Users/user/freezer/lib/sample/products.freezed.dart
┃  ┣━━ 🎉 /Users/user/freezer/lib/sample/products.g.dart
┃  ┣━━ 🎉 /Users/user/freezer/lib/sample/shop.dart
┃  ┣━━ 🎉 /Users/user/freezer/lib/sample/shop.freezed.dart
┃  ┗━━ 🎉 /Users/user/freezer/lib/sample/shop.g.dart
┗━━ 6 files in 5.5022 seconds

And you can see generated dart codes in the .lib folder like below.

.
├── analysis_options.yaml
├── design
│   └── sample
│       └── shop.freezer.json
├── lib
│   └── sample
│       ├── products.dart
│       ├── products.freezed.dart
│       ├── products.g.dart
│       ├── shop.dart
│       ├── shop.freezed.dart
│       └── shop.g.dart
├── pubspec.lock
└── pubspec.yaml

1.3. Contribution 🏆 #

If you would like to contribute to freezer, please create an issue or create a Pull Request.

There are many ways to contribute to the OSS. For example, the following subjects can be considered:

  • There are request parameters or response fields that are not implemented.
  • Documentation is outdated or incomplete.
  • Have a better way or idea to achieve the functionality.
  • etc...

You can see more details from resources below:

Or you can create a discussion if you like.

Feel free to join this development, diverse opinions make software better!

1.4. Support ❤️ #

The simplest way to show us your support is by giving the project a star at GitHub and Pub.dev.

You can also support this project by becoming a sponsor on GitHub:

1.5. License 🔑 #

All resources of freezer is provided under the BSD-3 license.

Copyright 2022 Kato Shinya. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided the conditions.

Note
License notices in the source are strictly validated based on .github/header-checker-lint.yml. Please check header-checker-lint.yml for the permitted standards.

1.6. More Information 🧐 #

freezer was designed and implemented by Kato Shinya (@myConsciousness).

24
likes
0
pub points
67%
popularity

Publisher

verified publishershinyakato.dev

Automatically generates object classes supported by the freezed library directly from JSON files.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

build_runner, dart_style, freezed_annotation, json_annotation

More

Packages that depend on freezer