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

Support Dart 2.0 #49

Closed rootext closed 6 years ago

rootext commented 6 years ago

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

eredo commented 6 years ago

Adding support for 2.0 isn't easy and comes with some great changes to the API of dartson (because transformers are no longer supported and builder come with some API and usage changes). There's currently an ongoing discussion in #48 . It would be great if you contribute some insights on how you're using dartson and why you are using it.

I'll definitely provide a newer version of dartson which will support 2.0. However I'm currently struggling in regards of how the API will change and what the benefits of dartson compared to other libraries like json_serializable will be.

rootext commented 6 years ago

I use dartson to parse glTF files. Main benefit compare to other libraries is easy to use:

  1. It just works - one line of code and JSON is deserialized.
  2. No configuration, no additional build steps, no annotations, no boilerplate code etc.
  3. Familiar experience from Java.

To my mind, it much more important than all other features. It is a reason why I use dartson.

I see no reason to write additional code for all my 30 classes to make them serializable using json_serializable. In all other languages there are commonly used libraries, which can serialize/deserialize classes without additional annotations/code. In Dart it is only dartson (as I know).

eredo commented 6 years ago

Thanks for the feedback! This is valuable input. So you're using the Dart VM and not compile to JavaScript?

Based on the current planning, there will be additional build steps in order to support cross platform compatibility. However it might be possible to keep this as small as possible or even only for web targets.

rootext commented 6 years ago

So you're using the Dart VM and not compile to JavaScript?

Correct. Desktop only - Windows and Linux. As I see it isn't popular.

By the way, dartson works with SDK 2.0.0-dev.54.0.

rootext commented 6 years ago

@eredo, I've just locally replace dynamic to Object in type_transformer.dart+simple_type_transformer.dart and JSON to JsonCodec in dartson.dart+dartson_static.dart and the following code compiles and works with SDK 2.0 now:

import 'package:dartson/dartson.dart';

class A {
  int b;
}

void main() {
  var a = new Dartson.JSON().decode('{"b": 1}', new A());
}

How are transformers used in Dartson? Is it required part of Dartson? Is it possible to release light version of Dartson compatible with SDK 2.0? Sorry for noob question.

eredo commented 6 years ago

Transformers are only used for dart2js compilation using previous pub build which is no longer compatible. We can go ahead and provide a separate version for now, which only supports VM usage for now.

rootext commented 6 years ago

I see. VM only usage isn't so poular, I belive. So it's up to you. Locale patched version works for me. Thank you for answer.

On Tue, Aug 14, 2018, 12:46 Eric Schneller notifications@github.com wrote:

Transformers are only used for dart2js compilation using previous pub build which is no longer compatible. We can go ahead and provide a separate version for now, which only supports VM usage for now.

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/eredo/dartson/issues/49#issuecomment-412816622, or mute the thread https://github.com/notifications/unsubscribe-auth/ABf5bOgXTjGy-4784MrQlp45clcM79dvks5uQpyRgaJpZM4VDuyl .

eredo commented 6 years ago

To keep you posted. I'm working on a new alpha version, which should support current functionality but requires small amount of builder setup. I'll probably have something released by the weekend.

koliyo commented 6 years ago

I have the same need, VM only usage. An updated version would be very appreciated!

eredo commented 6 years ago

The latest version 1.0.0-alpha now supports dart 2. Please check the README.md for the setup instructions.

eredo commented 6 years ago

Closing this. For new issues related to 1.0.0-alpha create a new issue please. For further design discussions and usage experience use #48 please.

rootext commented 6 years ago

Thank you