View Javadoc
1   /* 
2    * Copyright (C) 2016 Hobrasoft s.r.o.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package cz.hobrasoft.pdfmu.jackson;
18  
19  import com.fasterxml.jackson.annotation.JsonInclude;
20  import com.fasterxml.jackson.annotation.JsonInclude.Include;
21  import com.fasterxml.jackson.annotation.JsonProperty;
22  import com.fasterxml.jackson.annotation.JsonPropertyDescription;
23  
24  /**
25   *
26   * @author <a href="mailto:filip.bartek@hobrasoft.cz">Filip Bartek</a>
27   */
28  public class RpcResponse {
29  
30      @JsonPropertyDescription("A String specifying the version of the JSON-RPC protocol. MUST be exactly \"2.0\".")
31      @JsonProperty(required = true)
32      public final String jsonrpc = "2.0";
33  
34      @JsonPropertyDescription("It MUST be the same as the value of the id member in the Request Object (String, Number or Null).\n"
35              + "If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.")
36      @JsonProperty(required = true)
37      public final Object id = null;
38  
39      // Either `result` or `error` must be non-null and the other one must be null.
40      @JsonPropertyDescription("This member is REQUIRED on success.\n"
41              + "This member MUST NOT exist if there was an error invoking the method.\n"
42              + "The value of this member is determined by the method invoked on the Server.")
43      @JsonInclude(Include.NON_NULL)
44      private Result result;
45  
46      @JsonPropertyDescription("This member is REQUIRED on error.\n"
47              + "This member MUST NOT exist if there was no error triggered during invocation.")
48      @JsonInclude(Include.NON_NULL)
49      private RpcError error;
50  
51      public RpcResponse(Result result) {
52          assert result != null;
53          this.result = result;
54      }
55  
56      public RpcResponse(RpcError error) {
57          assert error != null;
58          this.error = error;
59      }
60  
61      public Result getResult() {
62          return result;
63      }
64  
65      public RpcError getError() {
66          return error;
67      }
68  }