dart-league / dson Goto Github PK
View Code? Open in Web Editor NEWdart library which converts Dart Objects into their JSON representation
License: Apache License 2.0
dart library which converts Dart Objects into their JSON representation
License: Apache License 2.0
I had to use @Property("renamed") and change the type of the otherName to String from bool. Also, the double dot notation did not work in the creation and assignment in the EntityClass constructor.
Hi,
I'm trying to serialize the object EVendor below into json, but I get an exception "the getter isEnum was called on null". Follow the object I'm trying to serialize below:
part 'package:ucount_flutter/entities/evendor.g.dart';
@serializable
class EVendor extends _$EVendorSerializable{
int id;
int userID;
int categoryID;
String name;
String description;
DateTime dateInserted;
EVendor({this.name, this.id});
noSuchMethod(Invocation invocation) {
super.noSuchMethod(invocation);
}
}
Exception
16:54:30.655 1 finer runtime.gc collection time 141ms • 43,4MB used of 59,5MB • isolates/766702422
16:54:47.908 2 finer runtime.gc collection time 160ms • 44,2MB used of 60,2MB • isolates/766702422
16:54:50.718 3 info flutter.tools I/flutter (12459): Salvou form:sdfdd
16:54:56.126 4 info flutter.tools E/flutter (12459): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
16:54:56.126 5 info flutter.tools E/flutter (12459): NoSuchMethodError: The getter 'isEnum' was called on null.
16:54:56.126 6 info flutter.tools E/flutter (12459): Receiver: null
16:54:56.126 7 info flutter.tools E/flutter (12459): Tried calling: isEnum
16:54:56.126 8 info flutter.tools E/flutter (12459): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
16:54:56.126 9 info flutter.tools E/flutter (12459): #1 _serializeObject (file:///C:/Users/tezine/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.0+1/lib/src/serializer.dart:114:18)
16:54:56.126 10 info flutter.tools E/flutter (12459): #2 objectToSerializable (file:///C:/Users/tezine/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.0+1/lib/src/serializer.dart:69:12)
16:54:56.126 11 info flutter.tools E/flutter (12459): #3 toJson (file:///C:/Users/tezine/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.0+1/lib/src/serializer.dart:27:28)
16:54:56.126 12 info flutter.tools E/flutter (12459): #4 _AppModel&Model&BaseModel&TransactionsModel&VendorsModel.insertVendor (package:ucount_flutter/models/vendors_model.dart:21:14)
16:54:56.126 13 info flutter.tools E/flutter (12459): <asynchronous suspension>
16:54:56.126 14 info flutter.tools E/flutter (12459): #5 VVendorsAddEditState._btnSaveClicked (package:ucount_flutter/views/vendors/vvendors_add_edit.dart:124:16)
16:54:56.126 15 info flutter.tools E/flutter (12459): #6 VVendorsAddEditState.build.<anonymous closure>.<anonymous closure> (package:ucount_flutter/views/vendors/vvendors_add_edit.dart:37:28)
16:54:56.126 16 info flutter.tools E/flutter (12459): #7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:494:14)
16:54:56.126 17 info flutter.tools E/flutter (12459): #8 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:549:30)
16:54:56.126 18 info flutter.tools E/flutter (12459): #9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
16:54:56.126 19 info flutter.tools E/flutter (12459): #10 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
16:54:56.126 20 info flutter.tools E/flutter (12459): #11 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
16:54:56.126 21 info flutter.tools E/flutter (12459): #12 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
16:54:56.126 22 info flutter.tools E/flutter (12459): #13 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
16:54:56.126 23 info flutter.tools E/flutter (12459): #14 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
16:54:56.126 24 info flutter.tools E/flutter (12459): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
16:54:56.126 25 info flutter.tools E/flutter (12459): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
16:54:56.126 26 info flutter.tools E/flutter (12459): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
16:54:56.126 27 info flutter.tools E/flutter (12459): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
16:54:56.126 28 info flutter.tools E/flutter (12459): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
16:54:56.126 29 info flutter.tools E/flutter (12459): #20 _invoke1 (dart:ui/hooks.dart:134:13)
16:54:56.128 30 info flutter.tools E/flutter (12459): #21 _dispatchPointerDataPacket (dart:ui/hooks.dart:91:5)
Here is my pubspec.yaml:
dependencies:
flutter:
sdk: flutter
path_provider: ^0.4.1
intl: ^0.15.7
sqflite: any
scoped_model: ^0.3.0
navigate: ^0.0.7
dson: ^0.15.0+1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
# flutter_test:
# sdk: flutter
intl_translation: ^0.16.8
build_runner: ^0.8.10
Any ideas? I'm running flutter 0.5.1 and dart 2.0.0 dev 58
Thank you,
Bruno.
There seems to be no support for enums, which would be nice. Now I get the error
Class 'OrderStatus' has no instance getter 'Todo'.
NoSuchMethodError: method not found: 'Todo'
Receiver: Instance of 'OrderStatus'
Arguments: []
dart:mirrors _LocalInstanceMirror.getField
package:dson/src/serializer.dart 124:37 _pushField
package:dson/src/serializer.dart 94:9 _serializeObject.<fn>
dart:collection _HashVMBase&MapMixin&&_LinkedHashMapMixin.forEach
package:dson/src/serializer.dart 93:23 _serializeObject
package:dson/src/serializer.dart 53:12 objectToSerializable
package:dson/src/serializer.dart 153:25 _pushField
package:dson/src/serializer.dart 94:9 _serializeObject.<fn>
dart:collection _HashVMBase&MapMixin&&_LinkedHashMapMixin.forEach
package:dson/src/serializer.dart 93:23 _serializeObject
package:dson/src/serializer.dart 53:12 objectToSerializable
dson
version: 0.15.5
dson_core
version: 0.15.4
Minimal example to reproduce bug:
/* test.dart */
import 'package:dson/dson.dart';
part 'test.g.dart';
main(List<String> args) {
toMap(new SimpleTest());
}
@serializable
class SimpleTest {
String x;
SimpleTest() {
x = null;
}
}
After build_runner build
, run the script and the following error was thrown:
Unhandled exception:
NoSuchMethodError: The getter 'isEnum' was called on null.
Receiver: null
Tried calling: isEnum
#0 Object.noSuchMethod (dart:core/runtime/lib/object_patch.dart:50:5)
#1 _serializeObject (file:/// [...] /AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.4/lib/src/serializer.dart:113:18)
#2 objectToSerializable (file:/// [...] /AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.4/lib/src/serializer.dart:69:12)
#3 toMap (file:// [...] /AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.4/lib/src/serializer.dart:42:5)
#4 main ( [...] test.dart:16:3)
#5 _startIsolate.<anonymous closure> (dart:isolate/runtime/lib/isolate_patch.dart:298:32)
#6 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/lib/isolate_patch.dart:171:12)
The error appears to be from this line in dson_core
, so I went to see the code. It seems that this instance variable somehow passed the primitive type check at line 11 (which in theory should block this null value):
bool isPrimitive(value) => value is String || value is num || value is bool || value == null;
Then this null value got to _serializeObject()
function, passed to the reflect()
function in built_mirrors_core
and returned as null instead of a ClassMirror
object.
I have little idea how this should be fixed though...
update: fixed format error
Using Dson 0.13.2
And this version of Flutter:
Flutter 0.5.2 • channel dev • https://github.com/flutter/flutter.git
Framework • revision 0a26ac0970 (3 days ago) • 2018-06-06 15:28:20 -0700
Engine • revision a83b37d35a
Tools • Dart 2.0.0-dev.60.0.flutter-a5e41681e5
Resulting this when compiling
compiler message: file:///myusersdir/.pub-cache/hosted/pub.dartlang.org/dson_core-0.13.2/lib/src/deserializer.dart:167:43: Error: The method 'add' isn't defined for the class 'dart._internal::EfficientLengthIterable<dynamic>'.
compiler message: Try correcting the name to the name of an existing method, or defining a method named 'add'.
compiler message: fillerList.forEach((item) => resultList.add(_convertValue(subType, item, "@LIST_ITEM")));
compiler message:
I has a json {"code":"90009","msg":"test","resultData":null}
, the resultData
is an object,
and the type is
$mkType = [
() => CommonBean<LoginToken>(),
{
$keyCommonBean1: [() => LoginToken(), LoginToken]
}
];
If resultData
is not null, there has no error
What do you think on rename:
serialize
to toJson
deserialize
to fromJson
deserializeList
to fromJsonList
objectToSerializable
to toMap
map
to fromMap
mapList
to fromMapList
Hi,
Currently, when I don't map a field I'm getting FieldNotFoundException.
furthermore, if I will extend my API response and add new fields to it, the fromJson will throw an exception (FieldNotFoundException) and it will not parse it to the relevant entity,
In addition, if I don't want to map all the fields in the entity the same result will happen.
There is a way maybe by an annotation that I can add on the Entity that will disable the throwing of the exception, the exclude and the ignore didn't help me.
Thanks
I've got exception when deserializing simple json:
Exception: Uncaught Error: type 'List<Object>' is not a subtype of type 'List<InstanceMirror>' of 'ams'.
Stack Trace:
#0 GetValueOfAnnotation._fromAnnotations (package:drails_commons/src/scanners.dart:16:43)
#1 GetValueOfAnnotation.fromDeclaration (package:drails_commons/src/scanners.dart:11:46)
#2 _fillObject.<anonymous closure> (package:dson/src/deserializer.dart:139:72)
#3 _HashVMBase&MapMixin&&_LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:340)
#4 _fillObject (package:dson/src/deserializer.dart:122:68)
#5 fromJson (package:dson/src/deserializer.dart:23:3)
The argument of GetValueOfAnnotation._fromAnnotations()
should probably be List<Object>
not List<InstanceMirror>
.
If the property id is not present in the object, How do I avoid getting the hashcode value?
We have to make it work somehow because polymer-dart 1.0.0-rc.2 now depends from it
I read the generated code, and the SerializableMap's code
please allow me using the easiest way
how suppout mulitiple Generic look like:List<Person<Person3, Person4>>,
i give the type :
$mkType = [
() => List<Person<Person3, Person4>>(),
[
() => Person<Person3, Person4>(),
[
{
$key_Person_1: [() => Person3(), Person3]
},
{
$key_Person_2: [() => Person4(), Person4]
}
]
]
];
then get an error :
onError type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Person4'
While having the #22 issue (and a few times before but because I was making another mistake) I had this error:
NoSuchMethodError: The getter 'name' was called on null.
Receiver: null
Tried calling: name
STACKTRACE:
#0 Object._noSuchMethod (dart:core-patch/object_patch.dart:43)
#1 Object.noSuchMethod (dart:core-patch/object_patch.dart:47)
#2 new IncorrectTypeTransform (package:dson/src/exceptions.dart:15:49)
#3 _convertValue (package:dson/src/deserializer.dart:235:17)
#4 _fillObject.<anonymous closure> (package:dson/src/deserializer.dart:147:22)
#5 List.forEach (dart:core-patch/array.dart:150)
#6 _fillObject (package:dson/src/deserializer.dart:134:23)
#7 _initiateClass (package:dson/src/deserializer.dart:346:10)
#8 _convertValue (package:dson/src/deserializer.dart:260:12)
#9 fromJson (package:dson/src/deserializer.dart:27:10)
It appears to come from:
IncorrectTypeTransform(Object value, String type, [String key = "unknown"]) :
_type = type,
_field = key,
_foundType = reflectType(value.runtimeType).name;
The problem appeared in the past when I forgot to call _initMirrors();
That was a hard one because the original Exception is hidden by this Exception in... Exception management.
However, I had it again when hitting #22 because type issues on native types are managed like that (on deserializer):
else if (valueType == String) {
if (value is String) {
return value;
} else {
throw new IncorrectTypeTransform(value, 'String', key);
}
} else if (valueType == num) {
if (value is num) {
return value;
} else {
throw new IncorrectTypeTransform(value, 'num', key);
}
} else if (valueType == int) {
if (value is int) {
return value;
} else {
throw new IncorrectTypeTransform(value, 'int', key);
}
} else if (valueType == double) {
if (value is double) {
return value;
} else {
throw new IncorrectTypeTransform(value, 'double', key);
}
} else if (valueType == bool) {
if (value is bool) {
return value;
} else {
throw new IncorrectTypeTransform(value, 'bool', key);
}
} else if (valueType == 'list') {
if (value is List) {
return value;
} else {
throw new IncorrectTypeTransform(value, 'list', key);
}
} else if (valueType == Map) {
if (value is Map) {
return value;
} else {
throw new IncorrectTypeTransform(value, 'Map', key);
}
but for me all these IncorrectTypeTransform()
returns the same Exception because reflectType(bool)
is null.
This is because base Dart types are not added to _classMirrors (and they don't need to, do they?)
Hi,
I'm sorry to bother again, but it seems enums are not being serialized.
TransactionType in the class below throws an exception when serializing to map:
library example.object_to_json; // required by dson
import 'package:dson/dson.dart';
import 'package:ucount_flutter/codes/cdefines.dart';
part 'package:ucount_flutter/entities/etransaction.g.dart';//required by dson
@serializable
class ETransaction extends _$ETransactionSerializable{
int id;
TransactionType transactionType;
int userID;
String title;
String description;
double total;
int categoryID;
int vendorID;
DateTime dt;
DateTime dateInserted;
ETransaction({this.userID,this.title,this.total,this.dt, this.transactionType, this.id});
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
Here is the TransactionType enum:
enum TransactionType {
expense,
income,
}
Follow the exception below:
14:42:59.439 4 info flutter.tools E/flutter ( 9976): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
14:42:59.439 5 info flutter.tools E/flutter ( 9976): NoSuchMethodError: The getter 'isEnum' was called on null.
14:42:59.439 6 info flutter.tools E/flutter ( 9976): Receiver: null
14:42:59.439 7 info flutter.tools E/flutter ( 9976): Tried calling: isEnum
14:42:59.439 8 info flutter.tools E/flutter ( 9976): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
14:42:59.439 9 info flutter.tools E/flutter ( 9976): #1 _serializeObject (file:///C:/Users/tezine/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.1/lib/src/serializer.dart:114:18)
14:42:59.439 10 info flutter.tools E/flutter ( 9976): #2 objectToSerializable (file:///C:/Users/tezine/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.1/lib/src/serializer.dart:69:12)
14:42:59.439 11 info flutter.tools E/flutter ( 9976): #3 _pushField (file:///C:/Users/tezine/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.1/lib/src/serializer.dart:180:25)
14:42:59.439 12 info flutter.tools E/flutter ( 9976): #4 _serializeObject.<anonymous closure> (file:///C:/Users/tezine/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.1/lib/src/serializer.dart:127:40)
14:42:59.439 13 info flutter.tools E/flutter ( 9976): #5 _ImmutableMap.forEach (dart:core/runtime/libimmutable_map.dart:45:8)
14:42:59.439 14 info flutter.tools E/flutter ( 9976): #6 _serializeObject (file:///C:/Users/tezine/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dson_core-0.15.1/lib/src/serializer.dart:126:23)
Hello.
I changed sample in extend_serializables
to generic to emulate my real case Derived => Base<T>
@serializable
class Person<T> extends _$PersonSerializable<T> {
int id;
T firstName;
String lastName;
DateTime dateOfBirth;
}
@serializable
// ignore: mixin_inherits_from_not_object
class Employee extends Person<String> with _$EmployeeSerializable {
double salary;
}
and got an issue:
[SEVERE] dson|dson_builder on example/bin/extend_serializables.dart:
Error formatting generated source code for 102dson/example/bin/extend_serializables.dartwhich was output to example/bin/extend_serializables.g.dart.
This may indicate an issue in the generated code or in the formatter.
Please check the generated code and file an issue on source_gen if appropriate.
Could not format because the source could not be parsed:
line 113, column 369: An equality expression can't be an operand of another equality expression.
╷
113 │ },fields: const {'salary': $$Employee_fields_salary,'id': $$Person_fields_id,'firstName': $$Person_fields_firstName,'lastName': $$Person_fields_lastName,'dateOfBirth': $$Person_fields_dateOfBirth},getters: const ['salary','id','firstName','lastName','dateOfBirth'],setters: const ['salary','id','firstName','lastName','dateOfBirth'],superclass: Person<String>
│
I notice that use 'fromMap' to convert json who contain list Model to dart List Model is not work.
It works OK, after i modify some code.
it should be:
List<Person> persons = fromMap([{"id": 1, "name": "John Doe"}], [List<Person>(), Person]);
Then it works well.
BTW: i think the Map conversion has same issue.
In VS, get error that {
"resource": "/C:/Users/Tom/DartProject2/lib/src/main.dart",
"owner": "dart",
"code": "uri_does_not_exist",
"severity": 8,
"message": "Target of URI doesn't exist: 'package:dson/dson.dart'.",
"source": "dart",
"startLineNumber": 4,
"startColumn": 8,
"endLineNumber": 4,
"endColumn": 32,
"tags": []
}
pretty much when i saw where it was coming from i said:
so how do i _initMirrors()
when I don't have an _initMirrors()
?
as i see it i need an _initMirrors()
function from somewhere but i don't have one. i see it in your examples.
update: I think i know where to get an _initMirrors()
function, but my main and all the things that need serializing are seperate, so i don't think it'll give my main.dart
a main.g.dart
with a _initMirrors()
function
Sorry to create this issue. But this is the package currently undergoing updates within your organization.
Best regards
Think about a list of random typed objects.
how would you deal with them?
Maybe try storing their type name with them.
I did it, but i don't know how your code works so i can't put it in yours, but a push in the right direction might be
{
'data': new SerializableBaconSomething(shouldDo:true,),
'type': SerializableBaconSomething,
}
Also, look at my package: server_client_comm
Hello,
1st, thanks for this package that has been really helpful!
Now I have a little issue with JSON ints that I want to map to double (because I know this can be "1.5", but when it's "1.0" the server returns just "1").
It's rejected by:
else if (valueType == double) {
if (value is double) {
return value;
} else {
throw new IncorrectTypeTransform(value, 'double', key);
}
}
This could be:
else if (valueType == double) {
if (value is double) {
return value;
} else if(value is int) {
return value.toDouble();
} else {
throw new IncorrectTypeTransform(value, 'double', key);
}
}
The conversion is possible the other way (double => int) but it's much more dangerous. Here we just cast to a larger class.
No seu caso específico, o pacote “flutter_fros_sak” depende da versão 1.17.1 da biblioteca “collection”, enquanto o pacote “dson” depende da versão “^1.17.2” da mesma biblioteca. Isso cria um conflito, pois essas versões não são compatíveis entre si.
Além disso, a versão 2.0.0 do pacote “dson” não oferece suporte à segurança de nulos (null safety), o que torna o pacote incompatível com o “flutter_fros_sak” e outros pacotes que dependem de null safety.
It would be nice if DSON supported immutable objects. I always make my data transfer objects immutable. This makes them safe to share in all code and also to cache. Here is an example:
class FooDto {
final Guid id;
final String name;
FooDto(this.id, this.name);
}
In order to deserialize the constructor must be called and the keys in the JSON matched to the names of the constructor params. I saw no examples of this (but have not tried so maybe it already works?).
this library seems doesn't support generic.
library entity.ApiResponse;
import 'package:dson/dson.dart';
part 'ApiResponse.g.dart';
@serializable
class ApiResponse<T> extends _$ApiResponseSerializable{
int code;
String toast;
String message;
T data;
}
and i compile it ,it's wrong.
══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
The following _CompileTimeError was thrown while handling a gesture:
'package:flutter_app/entity/ApiResponse.g.dart': error: line 70 pos 49: expression is not a valid
compile-time constant
const DeclarationMirror(name: 'data', type: T);
^
When the exception was thrown, this was the stack:
#0 HttpInfoParseState.build. (package:flutter_app/http_parse.dart:40:25)
#1 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:323:14)
#2 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:375:30)
#3 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
#4 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
#5 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
#6 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
#7 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
#8 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
#9 BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
#10 BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
#11 BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
#12 BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
#13 BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
#14 _invoke1 (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:127)
#15 _dispatchPointerDataPacket (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:85)
Handler: onTap
Recognizer:
TapGestureRecognizer#bc3a2(debugOwner: GestureDetector, state: possible, won arena, finalPosition:
Offset(47.7, 103.3), sent tap down)
This might be an issue with built_mirrors
Mirrors are not being generated if the class imported through an export.
setup
model.dart contains annotated class
intermediate.dart contains export "model.dart"
working
main.dart imports model.dart
main.g.dart has initClassMirrors({Control: ModelClassMirror});
Mirrors are generated
failing
main.dart imports intermediate.dart
main.g.dart has initClassMirrors({});
Mirrors are not generated, because the Model
doesn't seem to be picked up
serialization fails as _initMirrors() could not be generated
Given a standard flutter install, and a new user, I recommend some updated to the README.md
for setup/install and initial usage.
build_runner
as a dev_dependency within their pubspec.yaml
. For example
dev_dependencies:
build_runner:
flutter packages pub run build_runner build
library
naming, the part
naming, and the current requirement to have them all in a single file with the main()
function can be difficult to learn at the beginning. I recommend a review of these topics along with their limitations due to #30. Afterwards, to clarify the README.I just want to say
@serializable
Class AbsoluteEgg {
static String youJustGotBeaned = "tag your friends to totally bean them!";
}
youJustGotBeaned does not exist on class AbsoluteEgg
and yes I am being serious.
I followed along with the README, but it seems _initMirrors()
is not being generated if I define the following file:
lib/src/models/models.dart
library my_lib.models;
import 'package:dson/dson.dart';
part 'models.g.dart';
@serializable
class Person extends _$PersonSerializable {
int id;
}
tool/build.dart
import 'package:build_runner/build_runner.dart';
import 'package:dson/action.dart';
main() async
{
await build([dsonAction(const ['lib/src/models/**.dart'])], deleteFilesByDefault: true);
}
yields:
lib/src/models/models.g.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
part of my_lib.models;
// **************************************************************************
// Generator: DsonGenerator
// **************************************************************************
abstract class _$PersonSerializable extends SerializableMap {
int get id;
void set id(int v);
operator [](Object __key) {
switch (__key) {
case 'id':
return id;
}
throwFieldNotFoundException(__key, 'Person');
}
operator []=(Object __key, __value) {
switch (__key) {
case 'id':
id = __value;
return;
}
throwFieldNotFoundException(__key, 'Person');
}
Iterable<String> get keys => PersonClassMirror.fields.keys;
}
// **************************************************************************
// Generator: MirrorsGenerator
// **************************************************************************
_Person__Constructor([positionalParams, namedParams]) => new Person();
const $$Person_fields_id = const DeclarationMirror(name: 'id', type: int);
const PersonClassMirror = const ClassMirror(
name: 'Person',
constructors: const {
'': const FunctionMirror(name: '', $call: _Person__Constructor)
},
fields: const {
'id': $$Person_fields_id
},
getters: const [
'id'
],
setters: const [
'id'
]);
Notice the generated file lacks _initMirrors
, making it useless.
trying to add the package gives error
❰mac❙~/android(git✱≠✱main)❱✔≻ flutter pub add dson 4.4m Fri May 26 11:04:23 2023
The current Dart SDK version is 3.0.2.
Because * depends on dson any which doesn't support null safety, version solving failed.
The lower bound of "sdk: '<2.0.0 or >=2.0.0-dev <3.0.0'" must be 2.12.0 or higher to enable null safety.
For details, see https://dart.dev/null-safety
I tried this package just today and ran into the 'Missing concrete implementations of Map methods' error.
I noticed it stemmed from the serializable_core
package, and you've since pushed a new release for it.
I suggest you please update the dson
's pubspec as well, so us users can pull the new version 👍
Thanks for your efforts!
I thought reflectable was supposed to handle the dart2js case however when I run pub run test test/deserializer/deserializer_test.dart -p chrome
, it fails
00:28 +0 -1: deserialize: simple
UnimplementedError
dart:_internal JsLibraryMirror.libraryDependencies
package:reflectable/src/reflectable_mirror_based.dart 2269:14 ReflectableImpl._directlySupportedClasses
package:reflectable/src/reflectable_mirror_based.dart 2355:36 ReflectableImpl._supportedClasses.<fn>
dart:_internal JsLinkedHashMap.2.H.computeSignature.V.func
/tmp/dart_test_0eGINL/test_Dk1OSF/deserializer_test.dart.browser_test.dart.js.map 9:53 Object.J.putIfAbsent
package:reflectable/src/reflectable_mirror_based.dart 2354:12 ReflectableImpl._supportedClasses
package:reflectable/src/reflectable_mirror_based.dart 65:10 wrapClassMirrorIfSupported
package:reflectable/src/reflectable_mirror_based.dart 2215:14 ReflectableImpl.reflectType
Is dson supposed to work for browser application?
like, the other day, this happened: bla bla bla positionalParams
has a length of 0 RangeError
ooee blamo.
and it's been happening ever since.
I know it's easy to workaround importing dson library with 'as' keyword, just thinking maybe it would be better to avoid this at all by renaming it to something else, like DsonProperty, for example.
But think twice about that because it would be a breaking change. May be it would be enough to put a note about that in the docs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.