Back to project page rcdroid.
The source code is released under:
Copyright (c) 2013, Jamie Furness (jamie@jamierf.co.uk) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following...
If you think the Android project rcdroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.jamierf.rcdroid.http.handler; //from w w w . jav a2 s . c o m import com.google.common.net.HttpHeaders; import com.google.common.net.MediaType; import org.apache.http.HttpStatus; import org.codehaus.jackson.map.ObjectMapper; import org.webbitserver.HttpControl; import org.webbitserver.HttpHandler; import org.webbitserver.HttpRequest; import org.webbitserver.HttpResponse; public class JsonPOJOHandler implements HttpHandler { private static final ObjectMapper JSON = new ObjectMapper(); private final Object pojo; public JsonPOJOHandler(Object pojo) { this.pojo = pojo; } @Override public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception { final String json = JSON.writeValueAsString(pojo); // Write the pojo as json response.status(HttpStatus.SC_OK) .header(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()) .content(json) .end(); } }