chrisbu / dartwatch-JsonObject

JsonObject which allows dot notation access to JSON.parse'd objects. Read the article on http://www.dartlang.org/articles/json-web-service/
http://www.dartlang.org/articles/json-web-service/
MIT License
83 stars 25 forks source link

Exception: Class '_LocalClassMirror' has no instance getter 'getters'. #40

Open bitnick10 opened 8 years ago

bitnick10 commented 8 years ago

I'm newbie to dart.I wonder to know is this a bug or my fault. I'm using dart 1.12.1,dartium 1.11.3.0 and Intellij IDEA When I run the sample

class Other { String name = "My Name"; }

class Basic {
  String myString = "foo";
  int myInt = 42;
  Other name = new Other();
}

void main() {
  var basic = new Basic();
  objectToJson(basic).then((jsonString) => print(jsonString));
}

I got the error:

Exception: Class '_LocalClassMirror' has no instance getter 'getters'.

NoSuchMethodError: method not found: 'getters'
Receiver: Instance of '_LocalClassMirror'
Arguments: []package:json_object/src/mirror_based_serializer.dart:127 
_serializeObject@1003131927package:json_object/src/mirror_based_serializer.dart:53
 objectToSerializablepackage:json_object/src/mirror_based_serializer.dart:22 
objectToJsonindex.dart:56 main
stevenroose commented 8 years ago

I personally have no knowledge over the objectToJson method. @chrisbu wrote that one, so hopefully he can help.

As far as I can understand from the code, the code seems to be made for an older version of dart:mirrors that had a ClassMirror.getters property. The pubspec only mentions a minimum sdk version, so maximum, so probably a refactor has happened when around 1.0.

I have no interest in rewriting the code for the mirror-based code. In fact, now that it's broken, it might be better to remove it, that would also benefit JS compile size.

thosakwe commented 8 years ago

Yeah, I had this same error, so I went through the code. A lot of the mirror-based code in this repository is aimed for older versions of Dart. I didn't want to break the library for current users by changing the underlying code, so I just made my own library that does a similar thing.

So basically, this issue is fixed with thosakwe/json_god. The API is the tiniest bit different, though. Rather than using a JSONObject class, you can serialize/deserialize any Dart type, using the newer mirror API. Examples are in the repo README.md. It works in Dart2JS, too. Just include a @MirrorsUsed() annotation on your import to 'dart:mirrors'.

I've used it in a few smaller projects, and I think it does the job well for SDK ^1.0.0.

stevenroose commented 8 years ago

@thosakwe Off topic, but I've got this awesome Chrome extension:

thosakwe commented 8 years ago

Haha, that's funny. On Mar 11, 2016 9:05 AM, "Steven Roose" notifications@github.com wrote:

@thosakwe https://github.com/thosakwe Off topic, but I've got this awesome Chrome extension https://chrome.google.com/webstore/detail/nicolas-cage/fjgbnnhgejbfgfbofeohlffjlpceejlm?hl=en :

https://camo.githubusercontent.com/fe307972c2e45ea53edb4df807dbcc36b37a7380/68747470733a2f2f692e696d6775722e636f6d2f6c374e373142642e706e67

— Reply to this email directly or view it on GitHub https://github.com/chrisbu/dartwatch-JsonObject/issues/40#issuecomment-195378079 .