# Renderer

# Transform

You can use a JSON adapter to custom the response, recommended to use Google's GSON(opens new window)

import com.google.gson.Gson;

server.get("/json", ctx -> {
    val customer = CustomObject.builder()
                               .name("Tu Huynh").build();
    val gson = new Gson();
    return HttpResponse.of(customer)
    // You will get {"email": "abc@gmail.com", "name": "Tu Huynh"}

You can also use a XML transformer(opens new window) , to make your Jiny server speak XML or whatever format you want)

# Global Transform

You can also set a global custom response, which will be applied for all handlers in the server

import com.google.gson.Gson;

val server = HttpServer.port(1234)

# Template Engine

You can use a template engine as a custom render:

import com.github.jknack.handlebars.Handlebars;

public HttpResponse index(RequestContext ctx) throws IOException {
    val hb = new Handlebars();
    val template = hb.compileInline("<b>Hello {{this}}</b>");
    return HttpResponse.of(template.apply(ctx.getQuery().get("name")));