jsonize 1.0.0 copy "jsonize: ^1.0.0" to clipboard
jsonize: ^1.0.0 copied to clipboard

retractedoutdated

A json serializer class

A json serialize class to convert to and from json format [DateTime] and custom classes.

Features #

[Jsonize] solves the problem of serializing and deserializing into undefined structures.

By default [Jsonize] supports [DateTime] serialization in any place of your data structure '''dart List

[Jsonize] also supports your own classes. You can registrer a type or let your class implement the [Jsonizable] interface. '''dart class MyClass implements Jsonizable

// Jsonizable implementation @override String get jsonClassCode => "mc"; @override dynamic toJson() => str; @override MyClass? fromJson(value) => MyClass(value); }

void main() { Jsonize.registerClass(MyClass.empty()); Map<String, dynamic> myMap = { "my_num": 1, "my_str": "Hello!", "my_dt": DateTime.now(), "my_class": MyClass("here I am!") }; var jsonRep = Jsonize.toJson(myMap); var myDeserializedMap = Jsonize.fromJson(jsonRep); '''

[Jsonize.toJson] allows indentation for a bigger but more user readable json string.

For more comples examples like subclasses, please refer to the examples section.

Additional information #

Since current Dart implementation does not support reflection, [Jsonize] requires what I would define as two extra steps.

  1. register all your types/classes you want to serialize
  2. In case of implementing the [Jsonizable] interface, you will need to register a class instance (e.g. factory MyClass.empty() => ...)

I hope future Dart releases will suport better reflaction and type handling.

6
likes
0
points
42
downloads

Publisher

verified publishercabella.net

Weekly Downloads

A json serializer class

Homepage

License

unknown (license)

More

Packages that depend on jsonize