Example usage for io.vertx.core.json Json encodeToBuffer

List of usage examples for io.vertx.core.json Json encodeToBuffer

Introduction

In this page you can find the example usage for io.vertx.core.json Json encodeToBuffer.

Prototype

public static Buffer encodeToBuffer(Object obj) throws EncodeException 

Source Link

Document

Encode a POJO to JSON using the underlying Jackson mapper.

Usage

From source file:com.dinstone.vertx.web.core.DefaultExceptionHandler.java

License:Apache License

@Override
public void handle(Throwable t, RoutingContext context) {
    Map<String, Object> res = new LinkedHashMap<>();
    if (t == null) {
        res.put("code", "503");
        res.put("message", "The service is unavailable");
    } else {/*from w w w.j  av a2s . c om*/
        res.put("code", "500");
        res.put("message", t.getClass().getName() + ": " + t.getMessage());
    }

    HttpServerResponse response = context.response();
    response.setStatusCode(500).end(Json.encodeToBuffer(res));
}

From source file:com.dinstone.vertx.web.core.JsonMessageConverter.java

License:Apache License

@Override
public void write(Object result, RoutingContext context) throws IOException {
    context.response().putHeader("Content-Type", mediaType);

    if (result != null) {
        Buffer buffer = Json.encodeToBuffer(result);
        context.response().end(buffer);//  w w  w. j  a  v  a  2s  .  c om
    } else {
        context.response().end();
    }
}