Updated json_god

This commit is contained in:
thomashii 2021-05-15 09:31:17 +08:00
parent cfd34cbce0
commit cdec62a914
5 changed files with 33 additions and 16 deletions

View file

@ -1,3 +1,7 @@
# 4.0.1
* Added example
* Updated README.md
# 4.0.0 # 4.0.0
* Migrated to support Dart SDK 2.12.x NNBD * Migrated to support Dart SDK 2.12.x NNBD

View file

@ -5,7 +5,7 @@
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/json_god/LICENSE) [![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 # Installation
@ -34,14 +34,16 @@ print(json);
You can easily serialize classes, too. JSON God also supports classes as members. You can easily serialize classes, too. JSON God also supports classes as members.
```dart ```dart
import 'package:angel3_json_god/angel3_json_god.dart' as god;
class A { class A {
String foo; String foo;
A(this.foo); A(this.foo);
} }
class B { class B {
String hello; late String hello;
A nested; late A nested;
B(String hello, String foo) { B(String hello, String foo) {
this.hello = hello; this.hello = hello;
this.nested = A(foo); this.nested = A(foo);
@ -49,7 +51,6 @@ class B {
} }
main() { main() {
God god = God();
print(god.serialize( B("world", "bar"))); 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. 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)

View 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")));
}

View file

@ -89,10 +89,11 @@ deserialize(value, Type outputType, Deserializer deserializer,
throw ArgumentError( throw ArgumentError(
'${typeArguments[0].reflectedType} is not a class.'); '${typeArguments[0].reflectedType} is not a class.');
} }
} else if (value is Map) } else if (value is Map) {
return _deserializeFromJsonByReflection(value, deserializer, outputType); return _deserializeFromJsonByReflection(value, deserializer, outputType);
else } else {
return deserializer(value); return deserializer(value);
}
} catch (e, st) { } catch (e, st) {
logger.severe('Deserialization failed.', e, st); logger.severe('Deserialization failed.', e, st);
rethrow; rethrow;

View file

@ -1,5 +1,5 @@
name: angel3_json_god name: angel3_json_god
version: 4.0.0 version: 4.0.1
description: Easy JSON serialization and deserialization in Dart. description: Easy JSON serialization and deserialization in Dart.
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/json_god homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/json_god
environment: environment: