class Person {
int age;
String name;
Person boss;
Person[] children;
Person(this.age, this.name);
}
{
"age": 50,
"name": "Bob",
"boss": {
"age": 20,
"name": "Sally",
"children": [ { ... } ]
},
"children": [
{
"name": "Steve",
"age": 30,
"children": [ { .. } ],
},
{
"name": "Jane",
"age": 20,
"children": [ { ... } ]
}
}
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
I'm responsible for built_value; indeed, this is the approximate problem it's trying to solve.built_value is intentionally strict, however: as Danny mentioned the types have to be immutable. And, you can't have subclasses. The problem with subclasses and data types is that it breaks equality; I recommend using interfaces instead (no such thing in Dart, but you know what I mean; 'implement' instead of 'extend').
FWIW, I don't work for YouTube any more; I'm on the Dart team now :)
FWIW, I don't work for YouTube any more; I'm on the Dart team now :)Even better! :-)
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to a topic in the Google Groups "Dart Misc" group.
To unsubscribe from this topic, visit https://groups.google.com/a/dartlang.org/d/topic/misc/GQok_RQ0Ico/unsubscribe.
To unsubscribe from this group and all its topics, send an email to misc+uns...@dartlang.org.
This is because I've worked with code that used general serialization (think Java serialization) and had some serious problems with inconsistent data types. Some mutable, some immutable, some with equals/hashCode, some without, ... small projects can afford to give developers freedom, in large projects though it's a disaster waiting to happen.
BTW, built_value shouldn't be _too_ verbose -- did you discover that you don't have to write the Builder class if you don't want to? It can be fully generated. With that, and by adding extra factories by hand where you need them for convenience, it should be quite close. If there are any awkward cases I'd love to hear about them.
--
I haven't tried it, but it sounds like this might do what you need:
I guess that something nice for built_value would be to be able to help you bootstrap by generating classes from a specification of the data. There is an issue open for that
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
I'm really encouraged by all of the discussion and desires around this issue. I think there are a number of hurdles:1. Dart relies on being tree-shaken/minified to produce better performance and application size
That means there is no easy way to say "copy all fields from this object to this object", modulo either mirrors (ick) or codegen (see below).
2. Dartisans are opinionated on how code-generation should be done to create from/toMap/Json.
This is not - or at least - it requires an opinion on how to map that will be incompatible with other opinions:
class Animal {
Animal({
Species species,
List<Appendage> legs,
Map<String, Animal> relationships,
})
}
On Mon, 27 Feb 2017 at 18:40 Matan Lurey <ma...@lurey.org> wrote:I'm really encouraged by all of the discussion and desires around this issue. I think there are a number of hurdles:1. Dart relies on being tree-shaken/minified to produce better performance and application sizeSure; this seems to have been the main objection all along but it feels like a required feature is missing because of filesize optimisations. People are minifying JS today and still supporting JSON so it doesn't seem like an impossible problem (sure they don't have types, but you still can't change thing.name to thing.a so presumably JS minification libraries are selective; Dart could be too?).
That means there is no easy way to say "copy all fields from this object to this object", modulo either mirrors (ick) or codegen (see below).Codegen is a reasonable solution IMO. It kinda sucked before (transformers) but I think the new build stuff is pretty good.
2. Dartisans are opinionated on how code-generation should be done to create from/toMap/Json.Sure, but having limited JSON support and having to roll your own/use 3rd party for something complicated seems like a much better solution than nothing. Other frameworks have this - .NET's built-in JSON serialisers (all of them ;)) are pretty limited but they work in the majority of cases and people switch to something else (like json.net) when they need something more flexible.
That's true, though these aren't all json libraries - and something weird happens when you go to page 11, it highlights page 10?! But how many work, are still being maintained, don't require mirrors or transformers, are consistent in dev/production, authored by someone reputable, don't pull in boatloads of dependencies, etc.?
And how much time am I supposed to spend figuring out which one is best for me? It seems like a lot of work for something that is basically free in other languages.All these JSON packages (and all the SO questions about this) might mean there's a battery missing from Dart?(I also think "it's hard because of minification" and "we have tons of JSON packages" somewhat contradict each other!)
This is not - or at least - it requires an opinion on how to map that will be incompatible with other opinions:
class Animal {
Animal({
Species species,
List<Appendage> legs,
Map<String, Animal> relationships,
})
}I'm not sure exactly what you're referring to here? It's perfectly valid to crash at runtime if the provided data doesn't fit or if it's not possible to deserialise into a type (for ex. in .NET the deserialiser may throw if the class doesn't have a parameter-less constructors or setters). You don't have to provide a huge library that supports every combination of everything in order to be useful; but today you* don't even support the most basic case.
There are plenty of other languages/frameworks that do JSON and have all kinda of restrictions yet they're still incredibly useful and used in boatloads of projects!I'm sure the Dart team are sick of my opinions on JSON
so I don't want to drag this out; but it does seem to me like the value of a simple built-in (or Dart team pub package) JSON support is hugely underestimated by the Dart team. Everyone is using JSON for everything these days (I'm not saying this is good, but here we are) and this is a barrier that is frustrating to overcome (none of the current JSON solutions are trivial, not even for the most basic requirements). I think a Google-owned package that did basic JSON (via code-gen using build/watch scripts) would go a long way even if wasn't totally flexible.* by "you", I mean Google; this isn't personal ;-)
--