Dart Object -> JSON String failing to convert to JSON Dart Object -> JSON String failing to convert to JSON dart dart

Dart Object -> JSON String failing to convert to JSON


I think your problem is that you use print(req.toString());. Have you tried to do this:

objectToJson(req).then((jsonStr) => print(jsonStr)); Maybe this gives you a json string.

I personally feel like you actually SHOULD provide a toJson/toObject method because you have full control over what is serialized and how it is serialized (e.g. exclude private fields, null values, ...).

// EDIT

Because you use extends JsonObject toString() returns an empty map.

// EDIT

https://code.google.com/p/dart/issues/detail?id=6490 doesn't look like it is supported well. But then you can't use the json_object package anyway.

Exception: Uncaught Error: Class '_LocalClassMirror' has no instance getter 'getters'. This should be because the package requires experimental mirror features.

Using JSON.encode you cannot put an object into there. See https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:convert.JsonCodec#id_encode :

Either you specify the second parameter or implement .toJson().