Closed mnordine closed 8 years ago
Did you add the @Entity() annotation to your object classes (MyClass) which are serialized / deserialized?
Yes, here's my entity:
import 'package:dartson/dartson.dart';
@Entity()
class MyClass
{
int id;
}
And in the main package, main.dart
:
import 'package:dartson/dartson.dart';
import 'dart:convert' show JSON;
import 'package:entities/entities.dart';
main()
{
final dartson = new Dartson.JSON();
final map = {'id': 0};
MyClass decoded = dartson.decode(JSON.encode(map), new MyClass());
print(decoded.id);
}
and pubspec.yaml
:
name: 'web_dartson_test'
version: 0.0.1
description: An absolute bare-bones web app.
environment:
sdk: '>=1.0.0 <2.0.0'
dependencies:
browser: '>=0.10.0 <0.11.0'
dart_to_js_script_rewriter: '^1.0.1'
dartson: ^0.2.5
entities:
path: ../entities
transformers:
- dartson
- dart_to_js_script_rewriter
How does your pubspec.yaml look like?
It's there in the previous comment
Also, here's the pubspec.yaml
from the entities
library:
name: entities
description: A starting point for Dart libraries or applications.
version: 0.0.1
environment:
sdk: '>=1.0.0 <2.0.0'
dependencies:
dartson: any
dev_dependencies:
test: '>=0.12.0 <0.13.0'
Dartson currently doesn't support entities in dependencies, because transformers do not have access to those source files. Not sure if it works if you place the transformer also in your entities project. Haven't had the chance to test that yet.
What's interesting is that if I add dartson transformer to the entities
library in my simple test case presented here, it works. However, it doesn't work for my much more complex project. I'll try to nail down a simple test case that fails.
I figured it out. In my entity class file, I was using the following line for importing dartson
:
import 'package:dartson/dartson.dart' show Entity;
I needed to remove
show Entity
since the transformer adds other classes, such as
implements StaticEntity
hence the error you see above.
I'm getting the following error when using the transformer: