Skip to content

Instantly share code, notes, and snippets.

@ribrdb
Created June 15, 2010 22:36
Show Gist options
  • Select an option

  • Save ribrdb/439852 to your computer and use it in GitHub Desktop.

Select an option

Save ribrdb/439852 to your computer and use it in GitHub Desktop.
import javax.servlet.http.HttpServlet
import com.google.appengine.ext.duby.db.Model
class Posts < Model
property title, String
property contents, Text
end
import com.google.json.JsonSerializer
class EntitySerializer; implements JsonSerializer
def serialize(object, type, context)
key = Entity(object).getKey
context.serialize(key, key.getClass)
end
end
import com.google.json.GsonBuilder
class JsonServlet < HttpServlet
def doGet(request, response)
response.setHeader('Content-Type', 'text/plain')
response.getWriter.write(gson.toJson(Posts.all.run))
end
def gson
@gson ||= begin
klass = Entity.new('FooBar').getClass
GsonBuilder.new.registerTypeAdapter(klass, EntitySerializer.new).create
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment