Skip to content

Instantly share code, notes, and snippets.

@waleoyediran
Created August 15, 2014 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save waleoyediran/d12e44fa60736bb26522 to your computer and use it in GitHub Desktop.
Save waleoyediran/d12e44fa60736bb26522 to your computer and use it in GitHub Desktop.
A custom encoder that helps serialize AppEngine's GeoPt and datetime objects
import json
import datetime
from time import mktime
from google.appengine.ext import ndb
__author__ = 'oyewale'
class GeoDateEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
return int(mktime(obj.timetuple()))
elif isinstance(obj, ndb.GeoPt):
return {'lat': obj.lat, 'lon': obj.lon}
return json.JSONEncoder.default(self, obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment