Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/intonarumori/json_deserializer
https://github.com/intonarumori/json_deserializer
dart deserialization flutter
Last synced: 30 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/intonarumori/json_deserializer
- Owner: intonarumori
- License: mit
- Created: 2023-10-20T19:01:50.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-20T19:58:39.000Z (about 1 year ago)
- Last Synced: 2024-10-18T21:57:29.449Z (2 months ago)
- Topics: dart, deserialization, flutter
- Language: Dart
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON Deserialization
A simple JSON deserialization package for Dart and Flutter.
## Features
Very simple and manual JSON parsing, no code generations, no annotations.
## Getting started
- Add the package as a dependency:
```
flutter pub add json_deserializer
```## Usage
- Create your model objects and accompany each of them with a custom deserializer.
- Use `OptionalDeserializer` and `ListDeserializer` to parse optional values and lists respectively.```
class Person {
final String name;
final int age;
final Person? boss;
final List? children;Person({required this.name, required this.age, this.boss, this.children});
}class PersonDeserializer implements JSONDeserializer {
@override
Person fromJSON(json) {
return Person(
name: StringDeserializer().fromJSON(json['name']),
age: IntDeserializer().fromJSON(json['age']),
boss: OptionalDeserializer(PersonDeserializer()).fromJSON(json['boss']),
children:
OptionalDeserializer(ListDeserializer(PersonDeserializer())).fromJSON(json['children']),
);
}
}final data = {
"name": "George",
"age": 42,
"boss": {"name": "Arianne", "age": 55},
"children": [
{"name": "Nicky", "age": 11},
{"name": "Peter", "age": 13},
]
};final person = PersonDeserializer().fromJSON(data);
```
## License
MIT License.