Updated json_god
This commit is contained in:
parent
cfd34cbce0
commit
cdec62a914
5 changed files with 33 additions and 16 deletions
|
@ -1,3 +1,7 @@
|
|||
# 4.0.1
|
||||
* Added example
|
||||
* Updated README.md
|
||||
|
||||
# 4.0.0
|
||||
* Migrated to support Dart SDK 2.12.x NNBD
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/json_god/LICENSE)
|
||||
|
||||
|
||||
The ***new and improved*** definitive solution for JSON in Dart.
|
||||
The ***new and improved*** definitive solution for JSON in Dart. It supports synchronously transform an object into a JSON string and also deserialize a JSON string back into an instance of any type.
|
||||
|
||||
|
||||
# Installation
|
||||
|
@ -14,7 +14,7 @@ The ***new and improved*** definitive solution for JSON in Dart.
|
|||
|
||||
# Usage
|
||||
|
||||
It is recommended to import the library under an alias, i.e., `god`.
|
||||
It is recommended to import the library under an alias, i.e., `god`.
|
||||
|
||||
```dart
|
||||
import 'package:angel3_json_god/angel3_json_god.dart' as god;
|
||||
|
@ -34,14 +34,16 @@ print(json);
|
|||
|
||||
You can easily serialize classes, too. JSON God also supports classes as members.
|
||||
```dart
|
||||
import 'package:angel3_json_god/angel3_json_god.dart' as god;
|
||||
|
||||
class A {
|
||||
String foo;
|
||||
A(this.foo);
|
||||
}
|
||||
|
||||
class B {
|
||||
String hello;
|
||||
A nested;
|
||||
late String hello;
|
||||
late A nested;
|
||||
B(String hello, String foo) {
|
||||
this.hello = hello;
|
||||
this.nested = A(foo);
|
||||
|
@ -49,7 +51,6 @@ class B {
|
|||
}
|
||||
|
||||
main() {
|
||||
God god = God();
|
||||
print(god.serialize( B("world", "bar")));
|
||||
}
|
||||
|
||||
|
@ -105,11 +106,3 @@ HasAnInt invalid = god.deserialize('["some invalid input"]', HasAnInt);
|
|||
|
||||
An exception will be thrown if validation fails.
|
||||
|
||||
# Thank you for using JSON God
|
||||
|
||||
Thank you for using this library. I hope you like it.
|
||||
|
||||
Feel free to follow me on Twitter:
|
||||
[@thosakwe](http://twitter.com/thosakwe)
|
||||
|
||||
Or, check out [my blog](https://thosakwe.com)
|
19
packages/json_god/example/main.dart
Normal file
19
packages/json_god/example/main.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
import 'package:angel3_json_god/angel3_json_god.dart' as god;
|
||||
|
||||
class A {
|
||||
String foo;
|
||||
A(this.foo);
|
||||
}
|
||||
|
||||
class B {
|
||||
late String hello;
|
||||
late A nested;
|
||||
B(String hello, String foo) {
|
||||
this.hello = hello;
|
||||
this.nested = A(foo);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
print(god.serialize(B("world", "bar")));
|
||||
}
|
|
@ -89,10 +89,11 @@ deserialize(value, Type outputType, Deserializer deserializer,
|
|||
throw ArgumentError(
|
||||
'${typeArguments[0].reflectedType} is not a class.');
|
||||
}
|
||||
} else if (value is Map)
|
||||
} else if (value is Map) {
|
||||
return _deserializeFromJsonByReflection(value, deserializer, outputType);
|
||||
else
|
||||
} else {
|
||||
return deserializer(value);
|
||||
}
|
||||
} catch (e, st) {
|
||||
logger.severe('Deserialization failed.', e, st);
|
||||
rethrow;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel3_json_god
|
||||
version: 4.0.0
|
||||
version: 4.0.1
|
||||
description: Easy JSON serialization and deserialization in Dart.
|
||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/json_god
|
||||
environment:
|
||||
|
|
Loading…
Reference in a new issue