All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javaVertXServer.ResourceResponse.mustache Maven / Gradle / Ivy

The newest version!
package {{invokerPackage}}.util;

import {{invokerPackage}}.MainApiHeader;
import io.vertx.core.MultiMap;
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

public class ResourceResponse {
    MultiMap headers;
    T response;

    public ResourceResponse() {
        super();
        this.headers = MultiMap.caseInsensitiveMultiMap();
    }

    public ResourceResponse addHeader(MainApiHeader header) {
        if (header.getValue() != null)
            this.headers.add(header.getName(), header.getValue());
        else
            this.headers.add(header.getName(), header.getValues());
        return this;
    }

    public ResourceResponse addHeader(String name, String value) {
        this.headers.add(name, value);
        return this;
    }

    public ResourceResponse addHeaders(String name, Iterable values) {
        this.headers.add(name, values);
        return this;
    }

    public ResourceResponse setResponse(T response) {
        this.response = response;
        return this;
    }

    public MultiMap getHeaders() {
        return headers;
    }

    public T getResponse() {
        return response;
    }

    public String toJson() {
        if(response == null || response instanceof Void) return null;
        if(response instanceof JsonObject) return ((JsonObject) response).encodePrettily();
        if(response instanceof JsonArray) return ((JsonArray) response).encodePrettily();
        return Json.encodePrettily(response);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy