jsonable 0.0.2+1

  • Readme
  • Changelog
  • Installing
  • new65

Jsonable (v0.0.2) #

to install:

dependencies:
  jsonable: ^0.0.2

what is Jsonable? #

if you are interested in Jsoable with reflect read here

Jsonable is a library that deals with offering a simple way to manage dart classes fromJson and toJson, allowing the transpiration from dart to json. One of the main objectives and the philosophy of Jsoanble, is to remove the generated code making any object convertible into Json.

In the first version of Jsonable reflection was used, but this is not supported in the AOT compiler of dart.

Jsonable does not use reflection or even generated code.

how to use? #

Jsonable makes available a mixin mixin Jsonable within this mixin is the management of the Json scheme. only by extending our class with the mixin, the class gets the necessary methods, but if we don't indicate the members of json, using "toJson" or "toMap" will be an empty Map / string. ({})

let's see an example:

import "package:jsonable/jsonable.dart";

class Person with Jsonable {
 JString name;
 JString surname;
  Person({String name, String surname}) {
    this.name = this.jString("name", initialValue: name);
    this.surname = this.jString("surname", initialValue: surname);
  }
}

main() {
  var p = Person(name: "Nico", surname: "Spina");
  print(p.toJson());
  // output: {"name":"Nico","surname":"Spina"}
}

Jsonable implements different types to represent the whole Json structure:

  • JString
  • JNum
  • JBool
  • JClass<E extends Jsonable>
  • JList<E>
  • JDynamic *experimental
  • JMap *experimental

Jsonable records these types and serializes and deserializes the structure based on these types

The functions provided by Jsonable:

  • JClass<E> jClass<E extends Jsonable>(keyname, JsonableConstructor constructor, {E initialValue})

    It returns aJClass is JType<Jsonable> in the generic of this type, extends Jsonable, moreover it requires the constructor a simple function that returns an instance of that type. Note: it will be instantiated immediately to the declaration if InitialValue is null

  • JList<E> jList<E>(dynamic keyname, {List<E> initialValue, JsonableConstructor constructor})

aJList represents a List that can contain any value, you can iterate overJList and you don't need to access the value via ".value", in this type the constructor parameter becomes mandatory if you are using a Jsonable as generic are not allowed types of data other than: bool, string, num, int, double, map, list,

  • JString jString(dynamic keyname, {String initialValue})

    Return a JType <String> then manage a String type in the schema with fromJson will assign the value only if it is a String, in toJson it will assign a String, you can assign only String values via ".value"

  • JCool jBool(dynamic keyname, {bool initialValue})

    Return a JType <bool> then manage a bool type in the schema with fromJson will assign the value only if it is a bool, in toJson it will assign a bool, you can assign only bool values via ".value"

  • JNum jNum(dynamic keyname, {num initialValue})

    Return a JType <num> then manage a num type in the schema with fromJson will assign the value only if it is a num, in toJson it will assign a num, you can assign only num values via ".value"

  • JMap jMap(dynamic keyname, {Map initialValue})

    Return a JType <Map<E,R>> then manage a Map<E,R> type in the schema with fromJson will assign the value only if it is a Map<E,R>, in toJson it will assign a Map<E,R>, you can assign only Map<E,R> values via ".value"

  • JDynamic jDynamic(dynamic keyname, {dynamic initialValue})

    Return a JType <dynamic> then manage a dynamic type in the schema with fromJson will assign the value only if it is a dynamic, in toJson it will assign a dynamic, you can assign only dynamic values via ".value"

  • dynamic jOnce(keyname, Jsonable value) *experimental

    jOnce Returns the same value that passes in the value, the value you pass:

    it is inserted inside the Json schema, in a JClass that is not instantiated, further.

    This function is very useful when you are in a context like Flutter,

    where objects are called only in the widget build.

    Jonce returns your widget, without compromising it as long as the widget uses Jsonable

Performance #

in this second release I had particular attention to performance: Jsonable is less than 50% slower than native (generated). This test has not yet been made a benchmark with written tests. Tests were made by timing, the result was:

Note: I used dartVm not AOT

Conclusion #

If you want you can support the development by offering me a beer: paypal

If you can't buy beer, you can always leave me a star on github.

thanks!

0.0.2 #

Breaking change.

With the 0.0.1 management I started development with the reflection of Dart. This resulted in problems with AOT and consequently also with flutter. In version 0.0.2 all the APIs based on reflection in jsonable / withReflect have been moved

Announcements: 0.0.2 I set out to remove the generation of dart code from my projects, it's a practice I don't like. So in version 0.0.2 I start the creation of a module that is without generation and without reflection.

For more information read here.

0.0.1 #

  • frist publication. read: Readme.md

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  jsonable: ^0.0.2+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:jsonable/jsonable.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
46
Health:
Code health derived from static analysis. [more]
88
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
78
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

We analyzed this package on Oct 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:jsonable/jsonable.dart.

Health suggestions

Fix lib/src/typing/CJnum.dart. (-2.96 points)

Analysis of lib/src/typing/CJnum.dart reported 6 hints, including:

line 12 col 7: DO use curly braces for all flow control structures.

line 14 col 7: DO use curly braces for all flow control structures.

line 19 col 7: DO use curly braces for all flow control structures.

line 21 col 7: DO use curly braces for all flow control structures.

line 26 col 7: DO use curly braces for all flow control structures.

Fix lib/withReflect/validator/_validator.dart. (-2.48 points)

Analysis of lib/withReflect/validator/_validator.dart reported 5 hints:

line 11 col 7: DO use curly braces for all flow control structures.

line 18 col 11: DO use curly braces for all flow control structures.

line 26 col 11: DO use curly braces for all flow control structures.

line 35 col 11: DO use curly braces for all flow control structures.

line 44 col 11: DO use curly braces for all flow control structures.

Fix lib/src/typing/CJlist.dart. (-1.49 points)

Analysis of lib/src/typing/CJlist.dart reported 3 hints:

line 121 col 3: Avoid return types on setters.

line 141 col 3: Avoid return types on setters.

line 152 col 3: Avoid return types on setters.

Fix additional 6 files with analysis or formatting issues. (-5.48 points)

Additional issues in the following files:

  • lib/src/typing/CJstring.dart (3 hints)
  • lib/withReflect/annotation.dart (3 hints)
  • lib/src/typing/CJbool.dart (2 hints)
  • lib/src/scheme/fx.dart (1 hint)
  • lib/src/typing/CJmap.dart (1 hint)
  • lib/withReflect/validator/jsonValidator.dart (1 hint)

Maintenance suggestions

The package description is too short. (-12 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and jsonable.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
Dev dependencies
test any