Created
December 27, 2011 17:48
-
-
Save hakobera/1524535 to your computer and use it in GitHub Desktop.
Play で renderJSON の出力をカスタマイズする方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers; | |
import play.Play; | |
import play.mvc.Controller; | |
import play.mvc.results.RenderJson; | |
import com.google.gson.Gson; | |
import com.google.gson.GsonBuilder; | |
public class MyController extends Controller { | |
private static final Gson gson; | |
static { | |
GsonBuilder builder = new GsonBuilder(); | |
if (Play.mode.isDev()) { | |
builder.setPrettyPrinting().serializeNulls(); | |
} | |
builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss"); | |
gson = builder.create(); | |
} | |
protected static void renderJSON(Object object) { | |
throw new RenderJson(gson.toJson(object)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment