Closed crccheck closed 7 years ago
Serializing Decimal
s also doesn't work for Python's built-in JSON encoder. For some people, it makes sense to encode Decimal
s as JSON floats and for others it makes sense to encode as strings. I'm leaning towards suggesting what was said in https://github.com/frewsxcv/python-geojson/issues/49 and make your own encoder to treat Decimal
however you want it to be treated.
Yeah, I didn't test it, but I'm afraid that going to float then JSON would change the precision of the numbers. That's happened to me in the past. Since precision is important for lat/lng, and I know Django's JSONEncoder works with decimal, I opted to stay in Decimal
as long as possible.
I'd recommend subclassing python-geojson's encoder and adding in the appropriate logic to encode Decimal
s.
If you need help with any of that, let me know.
Example
Expected behavior:
Workaround