eredo / dartson

Dartson is a Dart library that can be used to convert Dart objects into a JSON string.
MIT License
79 stars 29 forks source link

Dartson is not working after dart2js compiling in sdk 1.23.0 #45

Closed rafbermudez closed 7 years ago

rafbermudez commented 7 years ago

I upgraded to sdk 1.23 (from 1.19) and dartson is not working after dart2js compiling.

Compiler displays this warning:

****************************************************************
* WARNING: dart:mirrors support in dart2js is experimental,
*          and not recommended.
*          This implementation of mirrors is incomplete,
*          and often greatly increases the size of the generated
*          JavaScript code.
*
* Your app imports dart:mirrors via:
*   main.template.dart => package:helpdesk_front => package:dartson => dart:mirrors
*   main.dart => package:helpdesk_front => package:dartson => dart:mirrors
*
* You can disable this message by using the --enable-experimental-mirrors
* command-line flag.
*
* To learn what to do next, please visit:
*    http://dartlang.org/dart2js-reflection
**************************************************************** 
floitschG commented 7 years ago

We are still investigating what could have changed since 1.19.

The warning message isn't very helpful. Could you maybe show the concrete class that isn't working anymore, and state what exactly isn't working?

thanks.

rafbermudez commented 7 years ago

When I upgraded to angular 3 I changed sdk to 1.23. But starting from a clean installation, this trivial test is not working after dart2js:

library test_dartson;

import '../lib/dartson.dart';
import 'package:test/test.dart';

void main() {
  var dson = new Dartson.JSON();

  test('trivial test', () {
    Map map = {"key1": "val1"};

    String str = dson.encode(map);
    expect(str, '{"key1":"val1"}');
  });
}

case A) dart mode pub run test test\my_test.dart 00:00 +1: All tests passed!

case B) javascript mode pub run test -pchrome test\my_test.dart

00:00 +0 -1: trivial test
  Expected: '{"key1":"val1"}'
    Actual: '{"key1":{}}'
     Which: is different.
  Expected: {"key1":"val1"}
    Actual: {"key1":{}}
                    ^
   Differ at offset 8

  package:test            Object.expect
  test\my_test.dart 13:5  main.<fn>

00:00 +0 -1: Some tests failed.

I think it's a problem with serialize. In dartson.dart _serializeMap(Map object):

eredo commented 7 years ago

Can you please show your pubspec. Dartson with dart2js should no longer use mirrors and instead use the transformer. It looks like you don't have the transformer set up properly.

rafbermudez commented 7 years ago

OMG! You're right. At some point by mistake I changed the transformer configuration.

Thanks so much for your help