Git Product home page Git Product logo

dartson's People

Contributors

eredo avatar jimirocks avatar kevmoo avatar nicolasgarnier avatar rightisleft avatar stevenroose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dartson's Issues

Is this project dead?

Hello, to me this project seems pretty useful, especially when developing web applications, however, seems in early stage and longer developed.

Can the owner clarify? If it is no longer maintained, what is a show stopper? - if it is the lack of time only I am willing to help. Or are there any technical obstacles?

Thanks

Subclass doesn't decode parent fields

Given the following file:

import 'package:dartson/dartson.dart';
import 'dart:convert' show JSON;

@Entity()
class Parent
{
  int id;
}

@Entity()
class Child extends Parent
{
  int blah;

  toString() => 'id: $id, blah: $blah';
}

main()
{
  final map = {
    'id': 0,
    'blah': 1
  };

  Child child = new Dartson.JSON().decode(JSON.encode(map), new Child());
  print(child);
}

It prints id: null, blah: 1

no TwoByteString transformer in pub.dartlang.org in version 0.2.7

dependencies:
  dartson: "^0.2.7"
transformers:
  - dartson

pub get

Then view in Dart Packages file dartson-0.2.7/src/core_transformers.dart.

...
  _qn(Object): _defaultSimpleTransformer,
  'dart.core._OneByteString': _defaultSimpleTransformer,
  'dart.core._Smi': _defaultSimpleTransformer
...

github.com:
lib/src/core_transformers.dart

  _qn(Object): _defaultSimpleTransformer,
  'dart.core._OneByteString': _defaultSimpleTransformer,
  'dart.core._TwoByteString': _defaultSimpleTransformer,
  'dart.core._Smi': _defaultSimpleTransformer

Pub issue

I'm seeing an odd issue with Dartson & mongo_dart.

I was running mongo_dart 0.1.46. - I need to upgrade it to mongo_dart 0.2.4

However, when i upgrade mongo_dart - i get the following error about dartson

Package mongo_dart has no versions that match 0.2.4 derived from:
- tickets depends on version 0.2.4

using: https://gist.github.com/rightisleft/ab9f49d2a6197658ca06
This is odd, as mongo_dart: '0.2.4' exists on pub.dartlang, and it works in isolation


By testing the removal of each individual package in pubspec.yaml, i was able to identify a conflict with dartson.

If i move dartson to the top of the dependency list i get the reverse:
https://gist.github.com/rightisleft/bd830c18df158921d6ea

Package dartson has no versions that match 0.2.4 derived from:
- tickets depends on version 0.2.4

Removing dartson all together allows for mongo_dart to install correctly.

Is there a known issue between the two libraries? Is there a conflict thats not getting surfaced?

serializing doubles fails

Example Code: https://github.com/rightisleft/dartson_double

I'm building up a DTO that accepts a double for a value. When serializing from dart, i get the following error:

/usr/local/Cellar/dart/1.10.1/libexec/bin/dart --ignore-unrecognized-flags --checked --package-root=/Users/jmurphy/projects/dartson_double/packages --enable-vm-service:50734 --trace_service_pause_events /Users/jmurphy/projects/dartson_double/bin/main.dart
Observatory listening on http://127.0.0.1:50734
Unhandled exception:
Stack Overflow
#0      StringBuffer.write (dart:core-patch/string_buffer_patch.dart:57)
#1      StringBuffer.StringBuffer (dart:core-patch/string_buffer_patch.dart:52)
#2      MirrorSystem.getName (dart:mirrors-patch/mirrors_patch.dart:63)
#3      Dartson._serializeObject (package:dartson/dartson.dart:47:21)
#4      Dartson._setField (package:dartson/dartson.dart:78:14)
#5      Dartson._serializeObject.<anonymous closure> (package:dartson/dartson.dart:121:11)
#6      _CompactLinkedHashMap.forEach (dart:collection-patch/compact_hash.dart)
#7      Dartson._serializeObject (package:dartson/dartson.dart:149:35)
#8      Dartson._setField (package:dartson/dartson.dart:78:14)
#9      Dartson._serializeObject.<anonymous closure> (package:dartson/dartson.dart:121:11)
#10     _CompactLinkedHashMap.forEach (dart:collection-patch/compact_hash.dart)
#11     Dartson._serializeObject (package:dartson/dartson.dart:149:35)
#12     Dartson._setField (package:dartson/dartson.dart:78:14)
#13     Dartson._serializeObject.<anonymous closure> (package:dartson/dartson.dart:121:11)
...
...
#14     MapView.forEach (dart:collection/maps.dart:194)
#15     Dartson._serializeObject (package:dartson/dartson.dart:117:35)
#16     Dartson.serialize (package:dartson/dartson.dart:78:14)
#17     Dartson._serializeList.<anonymous closure> (package:dartson/dartson.dart:96:30)
#18     MappedListIterable.elementAt (dart:_internal/iterable.dart:413)
#19     ListIterable.toList (dart:_internal/iterable.dart:219)
#20     Dartson._serializeList (package:dartson/dartson.dart:96:44)
#21     Dartson.serialize (package:dartson/dartson.dart:72:14)
#22     main (file:///Users/jmurphy/projects/dartson_double/bin/main.dart:13:33)
#23     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:255)
#24     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.d

Process finished with exit code 255
  • If i change field price in TransactionVO to a type of num, the errors persists
  • If i change field price in TransactionVO to a type of int, and assign an integer value, the errors resolves itself.

TypeTransformer: Use generic incorrectly

class DateTimeParser<T> extends TypeTransformer {
  T decode(dynamic value) {
    return DateTime.parse(value); // Warning "The return type 'DateTime' is not a 'T'"
  }

  dynamic encode(T value) {
    return value.toString();
  }
}

And I think it's better to write

registerTransformer(new DateTimeParser());

instead of

registerTransformer(new DateTimeParser<DateTime>());

which should be defined inside of class DateTimeParser

how to use with flutter?

I'm new to dart and new to flutter, but I know that flutter doesn't work with mirrors, and that dartson doesn't require mirrors. However, I don't know how to use dartson with flutter. I get the following errors:

$ flutter build apk
Building APK in release mode (android-arm-release)...      
Dart snapshot generator failed with exit code 254
Errors encountered while loading: 'dart:mirrors': error: line 1 pos 1: unexpected token 'Unhandled'
Unhandled exception:
^
'package:dartson/dartson.dart': error: line 10 pos 1: library handler failed
import 'dart:mirrors';
^
'file:///home/droundy/src/student-pairs/lib/main.dart': error: line 5 pos 1: library handler failed
import 'package:dartson/dartson.dart';
^
Error: 'dart:mirrors': error: line 1 pos 1: unexpected token 'Unhandled'
Unhandled exception:
^
'package:dartson/dartson.dart': error: line 10 pos 1: library handler failed
import 'dart:mirrors';
^
'file:///home/droundy/src/student-pairs/lib/main.dart': error: line 5 pos 1: library handler failed
import 'package:dartson/dartson.dart';
^
Failed to build AOT snapshot

I expect that this is simple to manage, but am not sure how to tell flutter that I want the non-mirrors version of dartson.

Thanks!

Missing a MirrorsUsed annotation

Hi,

To help get the size down for the compiled JS, please add a @MirrorsUsed annotation where you import dart:mirrors.

Since your library uses annotations, I think something like this should work:

@MirrorsUsed(metaTargets: const [DartsonEntity]);
import 'dart:mirrors';

Dependency issue with polymer.dart 1.0

Getting reflectable version mismatch. Please fix this.

pubspec.xml

name: 'GIS'
version: 0.0.1
description: GIS

environment:
  sdk: '>=1.0.0 <2.0.0'
dependencies:
  polymer: "^1.0.0-rc.2"
  polymer_elements: "^1.0.0-rc.1"
  route_hierarchical: "any"
  intl: "0.12.4+2"
  dartson: "0.2.4"
transformers:
- dartson
- polymer:
    entry_points: web/index.html

Error :

Working dir: P:\Workspaces\Workspace\GIS
C:\Dart\dart-sdk\bin\pub.bat get
Resolving dependencies...
Package reflectable has no versions that match >=0.3.1 <0.4.0 derived from:
- polymer 1.0.0-rc.2 depends on version ^0.3.1
- polymer_elements 1.0.0-rc.1 depends on version ^0.3.1
Process finished with exit code 1

Parse int value

I love this library, because i love strong-typed Object.

When i played with it, I created a MyClass and MySubClass

class MyClass{
  MySubClass child;
  int id;
  String name;
  MyClass();

}

class MySubClass{
  int id;
  String childName;
  MySubClass();

}

my json string is

{
  "id":1,
  "name":"MyClass",
  "child":{
    "id":10,
    "childName":"MySubClass"
  }
}

but when i parsed it, an error occured.

Cannot transform field "id" incorrect type. Requires [dart.core.int] and found [dart.core.int]

I know it works swapping int to num. But I'd like to know if it is possible use int

Dartson is not working after dart2js compiling in sdk 1.23.0

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
**************************************************************** 

dartson and polymer observable

Dartson works on this example class, but when I add extends Observable and @observable, it stops working. The object is just null. How to fix this?

Here is the modified example code:


@Entity()
class EntityClass extends Observable{
  @observable String name;
  String _setted;

  @Property(name:"renamed")
  bool otherName;

  @Property(ignore:true)
  String notVisible;

  List<EntityClass> children;

  set setted(String s) => _setted = s;
  String get setted => _setted;

  EntityClass();

  factory EntityClass.fromJson(string){
    var dson = new Dartson.JSON();
    EntityClass object = dson.decode(string, new EntityClass());
    return object;
  }
}

strange interference with polymer

i tried to use dartson with a polymer project. i got into serious troubles just including the dartson lib in pubspec.yaml and running pub get.

my yaml:
dependencies:
cookie: ">=0.0.4 <0.1.0"
polymer: ">=0.16.2 <0.17.0"
core_elements: ">=0.7.1+2 <0.8.0"
paper_elements: ">=0.7.1 <0.8.0"
route_hierarchical: ">=0.6.1+1 <0.7.0"
http: ">=0.11.2 <0.12.0"
dartson: ">=0.2.2 <0.3.0"

transformers:

  • polymer:
    entry_points: web/index.html
  • $dart2js:
    $include: "*/.polymer.bootstrap.dart"
  1. my app did not start at all and i got the following message:

No elements registered in a while, but still waiting on 7 elements to be registered. Check that you have a class with an @CustomTag annotation for each of the following tags: ...

i could fix this by removing an "enum DataType { ... }" from one of my polymer-element sources.

  1. after removing the enum, the app starts but now all of the ...Changed events do not fire anymore.

i did not even import dartson anywhere in the project, just included into the yaml and running pub get.
after removing dartson and running pub get again everything works as expected.

the polymer element which seems to be affected is using a core-list-dart element.
including dartson in the list of transformers does not make any difference.

Dartson writes to private fields instead of using getter and setters

I use a class with a private bool field and assign true to it. In the setter I make sure that the given value is not null (in case null is assigned in the deserialization process). The dart dev compiler always complains when there are bools with null values.

Dartson documentation points out, that it never serializes or deserializes private fields.

// private members are never serialized
String _private = "name";

Yet it does for me and it also ignores my public getter and setters;

@entity()
class MyClass implements StaticEntity {
bool _myPrivateBool = true;

bool get myBool => _myPrivateBool ;

void set myBool(bool value) {
if (value != null)
_myPrivateBool = value;
}

void dartsonEntityDecode(Map obj, TypeTransformerProvider dson) {
// ...
this._myPrivateBool = obj["_myPrivateBool"];
// ...
}

Problem encoding with UTF8

The following code fails

debugMsg = "โ†’";
Dartson dson = new Dartson.JSON();
assert(dson.encode(debugMsg) != "{}");

We need a true serializer for dart

Following up to the discussion on the dart tracker:

https://code.google.com/p/dart/issues/detail?id=16630

We need a true serializer for dart, something that works without having to recompile at every code change and that doesn't bloat and slow down the code. So please stop using Transformers and Mirrors, and try to make a runtime version of Dartson that can be called anywhere from code, and able to serialize/deserialize any dart object on the fly.

Using double in num properties causing Stack Overflow

As mentioned in #26, the following code will fail:

import 'package:dartson/dartson.dart';

@Entity
class Example {
  num takeDouble;
}

void main() {
  var dson = new Dartson.JSON();
  var jsonStr = dson.encode(new Example()..takeDouble = 1.11);

  // this will work
  var jsonStr2 = dson.encode(new Example()..takeDouble = 1);
}

Support Dart 2.0

I see the following compilation error if I try to use dartson with Dart SDK 2.0 (Dev):

file:///C:/Users/.../AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/dartson-0.2.7/lib/src/simple_type_transformer.dart:8:20: Error: The parameter 'value' of the method '_SimpleTypeTransformer::encode' has type dartson::_SimpleTypeTransformer::T, which does not match the corresponding type in the overridden method (dynamic).
Change to a supertype of dynamic (or, for a covariant parameter, a subtype).
dynamic encode(T value) => value;

Please add support for Dart 2

Environment:
dartson: 0.2.7
sdk: 2.0.0-dev.67.0

subtype error

I'm getting the following error when using the transformer:

Exception: type 'MyClass' is not a subtype of type 'StaticEntity' of 'clazz' where
  MyClass is from package:entities/src/entities_base.dart
  StaticEntity is from package:dartson/src/static_entity.dart

  Dartson.map   
  Dartson.decode    
  main  

Support references in serialization

This is issue is for tracking the request of supporting references within the serialization, based on the PR #23 .
However I'm not sure if this should land within dartson.

Future of dartson

There have been great improvements and changes in the dart ecosystem since the first version (0.1.0) of dartson was released in October 2013.
With the latest movement away from mirrors, transformers (barback) and towards code generation there are some great alternatives to dartson including:

https://pub.dartlang.org/packages/json_serializable
https://pub.dartlang.org/packages/built_value

With this in mind I was thinking about the future of dartson with the following points in mind:

  • Why do developers choose dartson over other packages?
  • What features should be provided in the future?
    • Support across multiple packages
    • Complex objects
    • Runtime class/type replacements
    • Versioning support
    • Default value serialization
  • Which packages are used commonly with dartson?
    • Should there some sort of adapters to these packages?
  • On which platform is dartson used or should be used? (server,web,mobile)

I need your support to answer these questions and to make a decision of where to go next with the development of dartson. Therefore I would really appreciate feedback to these questions or any additional input.

Please update da

Hello.

First of all, great plugin to manipulate JSON on Dart ;)

But I found a problem when trying to update to the 1.0.0 version. I followed the README at https://pub.dartlang.org/packages/dartson/versions/1.0.0-alpha+1

If I use in my pubspec.yaml this:

dependencies:
  dartson: ^1.0.0

It wil fail to install the package.

Running "flutter packages get" in app...
Because app depends on dartson ^1.0.0 which doesn't match any versions, version solving failed.

I fixed it, updating my pubspec.yaml to:

dependencies:
  dartson: ^1.0.0-alpha+1

There was some kind of confusion and the Dart package repository adopted 1.0.0-alpha+1 as the official version.

Could you update readme? I think other users may face this problem too.

Thanks!

Enable access to unknown properties

Introduce some mechanism for accessing unknown properties when decoding. For example in Jackson (java) there is @JsonAnySetter.

Dartson equivalent could be something like:

@Entity()
class MyEntity {
  @Property() String knownValue;
  @AnyProperty() Map<String, dynamic> unknownProperties;
}

How to run tests?

Running the transformer tests requires a test/tmp directory to exist with files

Handle base class when parse / serialize an object

It's useful when there are many common properties. For example:

abstract class BaseModel {
  int id;
  DateTime createdAt;
  DateTime updatedAt;
}

class Profile extends BaseModel {
  string name;
}

class Message extends BaseModel {
  string content;
}

malformed type: line 56 pos 26: type 'Map' is not loaded

Hi, just wanted to let you know something that I ran into and the solution. I was using a import "dart:core" as core; in my model class, for some reason. This made the dartson code not being able to find Map. The solution is not to do this weird import of dart built-in types. Maybe there is something you can do or warn about this, maybe not. Otherwise this is just for reference.

Exception:

void dartsonEntityDecode(Map obj, TypeTransformerProvider dson) {
                         ^
type '_CompactLinkedHashMap' is not a subtype of type 'malformed' of 'obj'.
Stack Trace:
#0      Project.dartsonEntityDecode (package:test_arrays_binding/model_project.dart:56:30)
#1      Dartson.map (package:dartson/dartson_static.dart:74:32)
#2      Project.Project.fromJsonString (package:test_arrays_binding/model_project.dart:29:34)
#3      PaneEdit.PaneEdit.created.<anonymous closure> (package:test_arrays_binding/pane_edit.dart:19:21)
#4      _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#5      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#6      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:270)
#7      _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:362)
#8      _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:237)
#9      Query._createStream.startListen.<anonymous closure> (package:firebase/src/firebase.dart:519:23)

Part of my model class code:


import 'package:polymer/polymer.dart';
import "dart:core" as core;
import 'package:dartson/dartson.dart';

/** Not documented yet. */
@Entity()
class Project extends Observable{
  /** Not documented yet. */
  @observable core.String hash;

  /** Not documented yet. */
  @observable core.String name = "New Project";

  /** Not documented yet. */
  @Property(ignore:true)
  @observable core.List<Category> categories = toObservable([]);

  //Project(this.hash, this.name, this.categories);

  Project.create(hash) : hash = hash, name = "New Project",categories = toObservable([]);

  Project.empty();

  Project();

  factory Project.fromJsonString(string){
    return new Dartson.JSON().map(string, new Project());
  }

  toString() => name;

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.