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

com.vmware.ovsdb.jsonrpc.v1.model.JsonRpcV1Response Maven / Gradle / Ivy

/*
 * Copyright (c) 2018 VMware, Inc. All Rights Reserved.
 *
 * This product is licensed to you under the BSD-2 license (the "License").
 * You may not use this product except in compliance with the BSD-2 License.
 *
 * This product may include a number of subcomponents with separate copyright
 * notices and license terms. Your use of these subcomponents is subject to the
 * terms and conditions of the subcomponent's license, as noted in the LICENSE
 * file.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

package com.vmware.ovsdb.jsonrpc.v1.model;

import static com.vmware.ovsdb.jsonrpc.v1.util.JsonRpcConstant.ERROR;
import static com.vmware.ovsdb.jsonrpc.v1.util.JsonRpcConstant.ID;
import static com.vmware.ovsdb.jsonrpc.v1.util.JsonRpcConstant.RESULT;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil;

/**
 * The response is a single object serialized using  JSON. It has three properties:
 * 

* result - The Object that was returned by the invoked method. This must be null in case there * was an error invoking the method. * error - An Error object if there was an error invoking the method. It must be null if there * was no error. * id - This must be the same id as the request it is responding to. *

* * @see JSON-RPC 1.0 Specification */ public class JsonRpcV1Response { private final JsonNode result; private final String error; private final String id; /** * Create a {@link JsonRpcV1Response} object. * * @param result RPC result as a {@link JsonNode} object. Should be null if there is an error * @param error RPC error. Should be null if there is no error * @param id response id that must be same as the request id */ @JsonCreator public JsonRpcV1Response( @JsonProperty(value = RESULT, required = true) JsonNode result, @JsonProperty(value = ERROR, required = true) String error, @JsonProperty(value = ID, required = true) String id ) { this.result = result; this.error = error; this.id = id; } /** * Create a {@link JsonRpcV1Response} object. * * @param result RPC result as an {@link Object}. Should be null if there is an error * @param error RPC error. Should be null if there is no error * @param id response id that must be same as the request id */ public JsonRpcV1Response(Object result, String error, String id) { this.result = JsonUtil.toJsonNode(result); this.error = error; this.id = id; } public JsonNode getResult() { return result; } public String getError() { return error; } public String getId() { return id; } @Override public String toString() { return getClass().getSimpleName() + " [" + "result=" + result + ", error=" + error + ", id=" + id + "]"; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy