Code Monkey home page Code Monkey logo

Comments (4)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.