synw / geojson

Utilities to work with geojson data in Dart
MIT License
36 stars 53 forks source link

make this lib compatible with standard dart json serialisation/deserialisation #9

Open ramsestom opened 5 years ago

ramsestom commented 5 years ago

To be compatible with the standard json serialisation/deserialisation feature of dart and the JsonSerializableGenerator, each geojson object (GeoJsonPoint, GeoJsonMultiPoint, GeoJsonLine...) of this lib should declare and expose a 'toJson()' and 'fromJson()' functions

synw commented 5 years ago

For toJson we could map the serializers to the method, that's not a problem. For fromJson there would be some refactor work to do, due to the way the parsing is made (it uses intermediary GeoJsonFeature objects).

Out of being standard what would be the benefit to have fromJson methods in models for this lib?

ramsestom commented 5 years ago

It is really usefull when you want to parse or output to json a larger structure that contains a GeoJsonObject. The JsonSerializableGenerator from the json_serializable package (https://github.com/dart-lang/json_serializable) relly on these functions to perform the serialisation/deserialisation of an object to json (you can override them by defining the custom functions they should point to in the @JsonKey annotation tag if they don't exist at your object level but it is way more convenient to have them already defined in your object to avoid having to override them each time. And for an object that represent a json object it definitively makes sense to have them defined (as there is a great chance this json object could be part of a larger json structure you would want to serialise/deserialise to json) )

synw commented 5 years ago

Thinking about it implementing fromJson does not seem feasible: the problem is that the parsing is always asynchronous as it is made in a separate isolate. Afaik there is no async constructors so I don't see how we could implement that.

@ramsestom do you have any idea about that?