-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling toMap() on an object with null fields throws an error #46
Comments
your error is because you didn't call your full code should look as fallow: library test; // don't forget to change the name of your library
import 'package:dson/dson.dart';
part 'test.g.dart';
main(List<String> args) {
_initMirrors(); // This call is needed to initialize mirrors before doing serialization/deserialization
toMap(new SimpleTest());
}
@serializable
class SimpleTest {
String x;
SimpleTest() {
x = null;
}
}``` |
Oh, my fault. Thanks, and sorry for taking your time!
Rynco Maekawa
--
…________________________________
From: [email protected] <[email protected]> on behalf of Luis Vargas <[email protected]>
Sent: Tuesday, March 26, 2019 10:29:44 AM
To: dart-league/dson
Cc: Rynco Li; Author
Subject: Re: [dart-league/dson] Calling toMap() on an object with null fields throws an error (#46)
your error is because you didn't call _initMirrors() function in your main:
your full code should look as fallow:
library test; // don't forget to change the name of your library
import 'package:dson/dson.dart';
part 'test.g.dart';
main(List<String> args) {
_initMirrors(); // This call is needed to initialize mirrors before doing serialization/deserialization
toMap(new SimpleTest());
}
@serializable
class SimpleTest {
String x;
SimpleTest() {
x = null;
}
}```
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#46 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AJyKr_kTCDTYpqeq0MoOMR7ZJxnUyxzAks5vaYYYgaJpZM4cFloZ>.
|
don't worry, it's cool to help users of my library |
Sorry, but the problem is here again. I have called More precisely, I'm working with the What should I do now? |
could you show me your full code or a full example? |
The issue occurs here: Future<ActionResult<Pic>> updateImgInfo(Pic newInfo, String id) async {
var _id = ObjectId.fromHexString(id);
var result = await picCollection.update(where.id(_id), newInfo.asMap());
newInfo.id = _id;
bool success = result['nModified'] > 0;
if (success)
return ActionResult()
..success = true
..data = newInfo
..affected = result['nModified'];
else
return ActionResult()..success = false;
} In this function, the This function is called by this line: This is the handling function of HTTP PUT of /// PUT `img/:id`
///
/// Updates image [id]'s data by [newInfo].
/// Requires authorization beforehand.
@Operation.put('id')
Future<Response> putImage(
@Bind.path('id') String id,
@Bind.body() Pic newInfo, [
@Bind.query('access_token') String tokenQuery,
@Bind.header('Access-Token') String tokenHeader,
]) async {
var result;
try {
result = await db.updateImgInfo(newInfo, id);
} catch (e, stack) {
logger.severe("Error in putImage()", e, stack);
throw Response.serverError(
body: {'error': e, 'message': result, 'stackTrace': stack});
}
return Response.ok(result);
} The rest of the handling process is managed by Aqueduct so I don't have access on them. The whole repository is here: https://github.com/01010101lzy/akali |
dson
version: 0.15.5dson_core
version: 0.15.4Minimal example to reproduce bug:
After
build_runner build
, run the script and the following error was thrown: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):Then this null value got to
_serializeObject()
function, passed to thereflect()
function inbuilt_mirrors_core
and returned as null instead of aClassMirror
object.I have little idea how this should be fixed though...
update: fixed format error
The text was updated successfully, but these errors were encountered: