Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Last active April 11, 2021 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukepighetti/ccecfcd144a79e8c38ead36c6c97a245 to your computer and use it in GitHub Desktop.
Save lukepighetti/ccecfcd144a79e8c38ead36c6c97a245 to your computer and use it in GitHub Desktop.
Testing jsonEncode with a class that has a toJson method.
import 'dart:convert';
void main() {
final foo = Foo('bar');
print(foo);
print(foo.foo);
print(jsonEncode(foo));
print(jsonEncode([foo, foo, foo]));
}
class Foo {
Foo(this.foo);
final String foo;
Map<String, dynamic> toJson() {
return {'foo': foo};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment