3 ms·
> Deserialising JSON onto a simple PODO with no inheritance, no mis-matching of properrty names, etc., is a pretty trivial requirement. This is not serializing
by DCKing 12y ago
> Deserialising JSON onto a simple PODO with no inheritance, no mis-matching of properrty names, etc., is a pretty trivial requirement.
This is not serializing into a PODO. This is serializing into a simple struct. Dart does not have simple structs, so you get no deserialization of simple structs.
Imagine that you write a core library function that does what you want. It cannot map arbitrary classes, but only a subset of classes that adheres to a "simple structure". The developers would then have to tell you which classes you can use it on, and which classes you can't. It would give you runtime errors when you happen to include inheritance somewhere in your project. It's an unmaintainable situation, and most safety of static checking would be gone. Not just in your project, but every project using that feature. Think of the developers' perspective. Why would they want to include such a fragile feature in the first place?
You could argue that Dart needs a "struct"-like construct just to support deserialization. Still the problems remain that that still has all the fragility problems of reflection. Good luck with convincing the developers about adding a language feature for that. They have already shown to not be receptive to that idea [1][2].
You are free to hack your way around typesafety, but you cannot make this a problem of the developers. A type safe language simply brings you inconvenience when you're trying to shoehorn dynamic data in static structure definitions. This is not the Dart developers' problem: increased type safety is their goal.
> Please tell me - how am I supposed to get data from a server into a data structure that will give me code-completion and type checking?
You either write your own code to do this or don't do this at all and just use the data in another shape. You can keep repeating this point all day long; you won't demonstrate why it is anything more than "nice to have", let alone that it's a "necessity".
> Other languages with types do this fine.
AFAIK only .NET-based languages and Go do this out of the box. Both can include this out-of-the-box because they are server oriented languages and can include all the complexity they want. Those languages don't care for the binary size of their applications as much as Dart applications.
[1]: https://groups.google.com/a/dartlang.org/forum/#!topic/misc/obmjDJJZq8A https://groups.google.com/a/dartlang.org/forum/#!topic/misc/...
[2]: https://code.google.com/p/dart/issues/detail?id=10374 https://code.google.com/p/dart/issues/detail?id=10374