django-geojson
django-geojson copied to clipboard
'Serializer' object has no attribute 'deserialize'
Thanks for this project. I'm playing around with importing it in the django shell to see how deserialization works on my data.
However, I get 'Serializer' object has no attribute 'deserialize'
if I try to import
>>> from djgeojson.serializers import Serializer as GeoJSONSerializer
>>> GeoJSONSerializer().deserialize()
Does this method not exist if I'm running from shell? The documentation is unclear to me.
The documentation looks wrong. And i'm not sure the Deserializer
is really tested because it looks like there is an exception which is not imported..
From looking through the tests, I'd say that you would need to do something like:
>>> from django.core import serializers
>>> serializers.deserialize('geojson', your_geojson)
Can you tell me if this works? Thanks.
I ran into the same error as @easherma when trying to de-serialize some GeoJSON that was returned from a geocoder API.
I tried @Gagaro's suggestion but it resulted in a different error:
{SerializerDoesNotExist}'geojson is a serialization-only serializer'
That's a pity. So far as I can tell there's no other library that will attempt to nicely convert some valid GeoJSON into a spatially aware Django model. Luckily I'm working with points so it's pretty easy to just parse them out from the JSON. But such a thing could be useful for more complex feature collections.
The thing is we do have a deserializer in the tests: https://github.com/makinacorpus/django-geojson/blob/master/djgeojson/tests.py#L69-L131
We also have a Deserializer
method, maybe you could try that one: https://github.com/makinacorpus/django-geojson/blob/master/djgeojson/serializers.py#L479-L521
I'm not sure what's up with all this.
I haven't been able to use the Deserializer class. Will keep trying though.
This part of the documentation is wrong, https://django-geojson.readthedocs.io/en/latest/advanced.html#low-level-deserializer
probably outdated right?
Would be nice to at least fix the docs. This was my first experience of using the whole makinacorpus Geodjango stack and it didn't inspire immediate confidence!
It seems to be that was never implemented