Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)
Turns an object into a JSONConverter-palatable form *before* serialization.

        def decorate(obj):
	"""
	Turns an object into a JSONConverter-palatable form *before* serialization.
	"""
	def add_type(obj, converter_type):
		"Converts a value into a map"
		return { 'json.converter.original.class': converter_type,
			'JSONConverter.value': obj }
	
	if hasattr(obj, 'json_map'):
		return obj.json_map()
	elif isinstance(obj, int):
		return add_type(obj, 'java.lang.Integer')
	elif isinstance(obj, basestring):
		return add_type(obj, 'java.lang.String')
	elif isinstance(obj, bool):
		return add_type(obj, 'java.lang.Boolean')
	elif isinstance(obj, date):
		# TODO: test
		from time import mktime
		return add_type(long(mktime(obj.timetuple()) * 1000), 'java.util.Date')
	elif isinstance(obj, (list, tuple)):
		conv_objs = [decorate(o) for o in obj]
		return {'JSONConverter.iscollection':
			True, 'JSONConverter.collection': conv_objs }
	elif isinstance(obj, dict):
		d = dict([(k, decorate(v)) for k,v in obj.items()])
		d['JSONConverter.map'] = True
		return d
	raise TypeError, "Don't know how serialize type %s (content: %s)" \
		% (type(obj), obj)
        


src/d/j/dj-cmdbuild-0.1dev-r23/django_cmdbuild/remoteapi/http.py   dj-cmdbuild(Download)
 
from django.utils import simplejson as json
from django_cmdbuild.serializer.jsonconverter import decorate, strip, ServerException
 
class Remote(object):
		"""
		import logging
		data = json.dumps(decorate(data))
		self.conn.request('POST', self.url, data, {
			'Content-Type': 'text/plain',