001/* 
002 * Copyright (C) 2016 Hobrasoft s.r.o.
003 *
004 * This program is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU Affero General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU Affero General Public License for more details.
013 *
014 * You should have received a copy of the GNU Affero General Public License
015 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
016 */
017package cz.hobrasoft.pdfmu.jackson;
018
019import com.fasterxml.jackson.annotation.JsonInclude;
020import com.fasterxml.jackson.annotation.JsonInclude.Include;
021import com.fasterxml.jackson.annotation.JsonProperty;
022import com.fasterxml.jackson.annotation.JsonPropertyDescription;
023
024/**
025 *
026 * @author <a href="mailto:filip.bartek@hobrasoft.cz">Filip Bartek</a>
027 */
028public class RpcResponse {
029
030    @JsonPropertyDescription("A String specifying the version of the JSON-RPC protocol. MUST be exactly \"2.0\".")
031    @JsonProperty(required = true)
032    public final String jsonrpc = "2.0";
033
034    @JsonPropertyDescription("It MUST be the same as the value of the id member in the Request Object (String, Number or Null).\n"
035            + "If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.")
036    @JsonProperty(required = true)
037    public final Object id = null;
038
039    // Either `result` or `error` must be non-null and the other one must be null.
040    @JsonPropertyDescription("This member is REQUIRED on success.\n"
041            + "This member MUST NOT exist if there was an error invoking the method.\n"
042            + "The value of this member is determined by the method invoked on the Server.")
043    @JsonInclude(Include.NON_NULL)
044    private Result result;
045
046    @JsonPropertyDescription("This member is REQUIRED on error.\n"
047            + "This member MUST NOT exist if there was no error triggered during invocation.")
048    @JsonInclude(Include.NON_NULL)
049    private RpcError error;
050
051    public RpcResponse(Result result) {
052        assert result != null;
053        this.result = result;
054    }
055
056    public RpcResponse(RpcError error) {
057        assert error != null;
058        this.error = error;
059    }
060
061    public Result getResult() {
062        return result;
063    }
064
065    public RpcError getError() {
066        return error;
067    }
068}