Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

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

Open
ramsestom opened this issue Oct 9, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@ramsestom
Copy link

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
Copy link
Owner

synw commented Oct 10, 2019

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
Copy link
Author

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 synw added the enhancement New feature or request label Oct 17, 2019
@synw
Copy link
Owner

synw commented Nov 4, 2019

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants