jpl_json_class 3.0.2 copy "jpl_json_class: ^3.0.2" to clipboard
jpl_json_class: ^3.0.2 copied to clipboard

An abstract class to assist with converting to and from JSON with various primitive parsers.

🛡️ Fork — Jeff Peiffer Legacy (jpl_) #

Este paquete (jpl_json_class) es un fork de json_class, originalmente creado por Jeff Peiffer y archivado (read-only) junto con toda la org peiffer-innovations.

El prefijo jpl_ significa Jeff Peiffer Legacy: mantenemos vivo el legado de estos paquetes, bumpeados a las últimas versiones de Dart/Flutter, en el monorepo jpl.

Licencia original conservada. El crédito del diseño y la implementación original es de Jeff Peiffer.

I'm done

Table of Contents

json_class #

Singular class that when extended can encode itself to a JSON compatible map or list. This also provides convenience functions to decode from a JSON compatible map or list to the actual data model.

Using the library #

Add the repo to your Flutter pubspec.yaml file.

dependencies:
  json_class: <<version>> 

Then run...

flutter packages get

Example #

import 'package:json_class/json_class.dart';
import 'package:meta/meta.dart';

@immutable
class Person extends JsonClass {
  Person({
    this.age,
    this.minor,
    this.firstName,
    this.lastName,
  });

  final int age;
  final bool minor;
  final String firstName;
  final String lastName;

  static Person fromDynamic(dynamic map) {
    // It's recommended to use dynamic over Map<String, dynamic> because it's
    // compatible with other types of map-like results such as Firebase Realtime
    // Database's values or the ones returned from sqlflite.
    Person result;

    if (map != null) {
      result = Person(
        age: JsonClass.parseInt(map['age']),
        minor: JsonClass.parseBool(map['minor']),
        firstName: map['firstName'],
        lastName: map['lastName'],
      );
    }

    return result;
  }

  static List<Person> fromDynamicList(Iterable<dynamic> list) {
    List<Person> results;

    if (list != null) {
      results = [];
      for (dynamic map in list) {
        results.add(fromDynamic(map));
      }
    }

    return results;
  }

  @override
  Map<String, dynamic> toJson() => JsonClass.removeNull({
    age: age,
    minor: minor,
    firstName: firstName,
    lastName: lastName,
  });
}

0
likes
150
points
12
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

An abstract class to assist with converting to and from JSON with various primitive parsers.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

intl, logging, meta

More

Packages that depend on jpl_json_class