2

Trying to run this code to serialize an object in JSON using dartson generates a Stack Overflow exception when using a double value in a member. How can i solve this problem?

 import 'package:dartson/dartson.dart';


    @MirrorsUsed(targets:const['example'], override:'*')
    import 'dart:mirrors';

    @Entity()
    class GeoFence {
      String label;
      num latitude;
      num longitude;
      num radius;
    }


    main(List<String> args) {
      var dson = new Dartson.JSON();

      GeoFence object = new GeoFence()
        ..label = "test"
        ..latitude = 46.2
        ..longitude = 12
        ..radius = 10;


      String jsonString = dson.encode(object);
      print(jsonString);
    }
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
GioLaq
  • 2,489
  • 21
  • 26

2 Answers2

2

It's a closed issue, but the serialization of double doesn't work yet GitHub issue

Alon Amir
  • 4,913
  • 9
  • 47
  • 86
GioLaq
  • 2,489
  • 21
  • 26
2

I tried your example and it looks like there's an issue with doubles used in "num" defined properties. Please try:

import 'package:dartson/dartson.dart';

@Entity()
class GeoFence {
  String label;
  double latitude;
  double longitude;
  double radius;
}


main(List<String> args) {
  var dson = new Dartson.JSON();

  GeoFence object = new GeoFence()
    ..label = "test"
    ..latitude = 46.2
    ..longitude = 12
    ..radius = 10;


  String jsonString = dson.encode(object);
  print(jsonString);
}

Also please notice that @MirrorUsed annotation is no longer required when using dartson. I'll update the issue on github and take a look at it asap.