Comments (4)
unfortunately, the json output is handled by post-processing the xml. this was
a convenient and easy way to add json support, but, as a consequence, any
number information is unavailable at the time the json output is generated. as
such, it's unlikely that this will be changed.
Original comment by [email protected]
on 18 Jun 2011 at 12:28
- Added labels: Type-Enhancement, Priority-Low
- Removed labels: Type-Defect, Priority-Medium
from appengine-rest-server.
I had a similar problem. I usually don't use xml for any of my web stuff, and I
also wanted to represent the datatype as much as possible. Writing your own
Model->Rest functions is an easy and quick way to do this.
Here is a sample of what I am doing
-------------------------------
import simplejson as json
class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if hasattr(obj, 'isoformat'): #handles both date and datetime objects
return obj.isoformat()
else:
return json.JSONEncoder.default(self, obj)
def toJSON(_object, default):
result = None
if isinstance(_object, list):
result = []
for item in _object:
_result = dict([(p, getattr(item, p)) for p in item.properties()])
_result['key'] = item.key().id_or_name()
result.append(_result)
else:
try:
result = dict([(p, getattr(_object, p)) for p in _object.properties()])
result['key'] = _object.key().id_or_name()
except:
LOG.exception("Error trying to convert %r to json", _object)
result = default
return json.dumps(result, cls=JSONEncoder)
--------------------
The above function toJSON will work with Model Objects, and the json string
will have proper (almost) datatypes.
Original comment by [email protected]
on 12 Dec 2011 at 9:49
from appengine-rest-server.
think i should be able to make this happen after all.
Original comment by [email protected]
on 29 Jun 2012 at 4:28
- Added labels: Milestone-Release-1.0.6
from appengine-rest-server.
This issue was closed by revision r79.
Original comment by [email protected]
on 30 Jun 2012 at 12:20
- Changed state: Fixed
from appengine-rest-server.
Related Issues (20)
- Implement Python Unit Tests HOT 1
- Package new version HOT 3
- No JSON object could be decoded HOT 4
- Setting caching = True causes AttributeError: 'Response' object has no attribute 'getvalue' HOT 4
- The server runs ik but the authorizer class you provided doest seem to work.I can still access my model without login. HOT 7
- Detailed Documentation HOT 10
- Problem with POST method HOT 7
- use <list> for metadata HOT 1
- ETag / If-None-Match support HOT 4
- JSON usage HOT 2
- Nested results using reference property HOT 5
- Initial Setup & Install HOT 2
- Allow using key name (or integer ID) when referencing entities HOT 3
- JSON Query responses that return one data object are not correctly serialised HOT 2
- GET Broken: Syntax error introduced in r121 HOT 1
- TypeError: unbound method set_response_content_type HOT 1
- Remove "Item" nodes in json HOT 12
- Paging and memcache HOT 1
- Need to return a count of the results in total. HOT 2
- Uploading images to BlobInfo HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from appengine-rest-server.