https://github.com/yrehim7/user_model_serialization
A lightweight and developer-friendly Dart project that shows how to handle JSON serialization for user models using both automated and manual approaches. Perfect for Flutter and Dart apps that need clean, structured data handling
https://github.com/yrehim7/user_model_serialization
dart flutter json json-serialization user-model
Last synced: 3 months ago
JSON representation
A lightweight and developer-friendly Dart project that shows how to handle JSON serialization for user models using both automated and manual approaches. Perfect for Flutter and Dart apps that need clean, structured data handling
- Host: GitHub
- URL: https://github.com/yrehim7/user_model_serialization
- Owner: yrehim7
- Created: 2022-12-08T09:03:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-08T12:36:12.000Z (over 1 year ago)
- Last Synced: 2025-07-19T01:53:07.799Z (12 months ago)
- Topics: dart, flutter, json, json-serialization, user-model
- Language: Dart
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dart User Model JSON Serialization
Welcome to the **Dart User Model JSON Serialization** repository!
This project provides a clean and efficient way to handle JSON serialization and deserialization for user-related data structures in Dart. It features two main components: `user.dart` and `user_model.dart`, each designed for a different level of data abstraction and complexity.
## Files Overview
### `user.dart`
- Defines a basic `User` class with fields like `name` and `email`.
- Uses the `json_annotation` package for automatic JSON serialization.
- Includes:
- `fromJson()` factory constructor for parsing from JSON.
- `toJson()` method for converting to JSON.
- This file requires code generation using the `build_runner` tool.
### `user_model.dart`
- Wraps the `User` class into a more detailed `UserModel`.
- Adds extra fields like `token`.
- Manually handles JSON serialization and deserialization logic.
- Offers helper methods for raw JSON string parsing (`fromRawJson` and `toRawJson`).
## How to Use
1. **Add Dependencies:**
In your `pubspec.yaml`:
```yaml
dependencies:
json_annotation: ^4.8.1
dev_dependencies:
build_runner: ^2.4.6
json_serializable: ^6.6.1