easy_json 1.0.1 easy_json: ^1.0.1 copied to clipboard
A JSON serialization library for Dart developers.
A JSON serialization library for Dart developers. #
Based on reflection (by
dart:mirrors
), serialized and parse json easily without generate code.
Usage #
A simple usage example:
import 'package:easy_json/easy_json.dart';
main() {
var simple = SimpleExample(
0x01001,
'name',
['item0'],
{'name0': 'value0'},
SimpleNested(0x02001),
);
var simpleEncoded = toJsonString(simple);
print(simpleEncoded);
var simpleDecoded = ofJsonString(SimpleExample, simpleEncoded);
print(simpleDecoded);
}
class SimpleExample {
final int id;
final String name;
final List<String> list;
final Map<String, dynamic> map;
final SimpleNested nested;
@JsonIgnore
final String ignored;
SimpleExample(
this.id,
this.name,
this.list,
this.map,
this.nested, [
this.ignored,
]);
}
class SimpleNested {
final int id;
SimpleNested(this.id);
}
Features and TODO List #
- toJson (serialized object without generate code)
- ofJson (parse from json map without generate code)
- nested (auto serialized and parse the nested type)
- @JsonIgnored (ingored some fields when serialized and parse)
- @JsonField (custom the
of
andto
function of some fields) - @JsonModel (custom the
of
andto
function of some class) - @EasJson<It, Json> (full support of explicit generic type)
- redirecting support (syntax like
factory Constructor = aConstructor
) - cache (cache the reflection shape of the model to speed up the next usage)