Skip to content

alexeyinkin/dart-dump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dump

Dumps any objects to structures of maps, lists, and scalars using mirrors.

The package provides two functions:

dumpJson

Converts any object to scalar, map, list, or their combination:

final toDump = [
  1,
  'string',
  Foo(
    b: false,
    d: 3.1415926,
    n: 456,
    s: 'def',
  ),
];

final dumped = dumpJson(toDump);
// Result:
// [
//   1,
//   'string',
//   {
//     '': 'Foo',
//     'b': false,
//     'd': 3.1415926,
//     'n': 456,
//     's': 'def',
//   },
// ]

The rules are:

  • null, int, double, bool, and String stay as they are.
  • Interable is converted to a list, each element is processed recursively.
  • Map is converted to another map with .toString() called on keys, values are processed recursively.
  • Any other object is converted to a map with the class name under '' key, an entry for each field including private, field values are processed recursively.

dumpString

Calls dumpJson and pretty-prints the result to a string.

Warning

All formats are subject to change. Use this to get a human-readable format of data or to compare objects in tests. Any stored result may be incompatible with future versions.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages