mirror_json 0.1.0 mirror_json: ^0.1.0 copied to clipboard
A Dart library for parsing JSON objects using reflection (dart:mirrors). Does not support Flutter.
✨ mirror_json #
A Dart library for parsing JSON objects using dart:mirrors
.
Important: This library does not work in Flutter.
🔨 Installation #
Add mirror_json
to your dependencies.
dependencies:
...
mirror_json:
Now get the packages.
pub get
🔮 Getting started #
mirror_json
uses a concept of Parsers. There are a bunch of parsers for simple types (int, double, String) already in the package, but in order to parse a class, you have to make a ClassParser
instance.
import 'package:mirror_json/mirror_json.dart';
@JsonParseable()
class MyClass {
...
}
void main() {
GlobalJsonParserInstance.initialize();
var parser = ClassParser<MyClass>();
// From json
var myObject = parser.fromJson({...});
// To json
var json = parser.toJson(myObject);
}
Woah, what just happened?
First, we initialized mirror_json
's main class, GlobalJsonParserInstance
. Then, we created a parser for MyClass
. Now you can use the parser to transform your JSON objects to MyClass
instances or MyClass
objects to JSON.
💡 Example #
See example under example
folder.
📚 Docs #
See docs here
📭 Contact me #
E-Mail: kk.erzhan@gmail.com