1 /*
2 * Copyright (C) 2008 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.gson;
18
19 /**
20 * A class representing a Json {@code null} value.
21 *
22 * @author Inderjeet Singh
23 * @author Joel Leitch
24 * @since 1.2
25 */
26 public final class JsonNull extends JsonElement {
27 /**
28 * singleton for JsonNull
29 *
30 * @since 1.8
31 */
32 public static final JsonNull INSTANCE = new JsonNull();
33
34 /**
35 * Creates a new JsonNull object.
36 * Deprecated since Gson version 1.8. Use {@link #INSTANCE} instead
37 */
38 @Deprecated
39 public JsonNull() {
40 // Do nothing
41 }
42
43 /**
44 * Returns the same instance since it is an immutable value
45 * @since 2.8.2
46 */
47 @Override
48 public JsonNull deepCopy() {
49 return INSTANCE;
50 }
51
52 /**
53 * All instances of JsonNull have the same hash code since they are indistinguishable
54 */
55 @Override
56 public int hashCode() {
57 return JsonNull.class.hashCode();
58 }
59
60 /**
61 * All instances of JsonNull are the same
62 */
63 @Override
64 public boolean equals(Object other) {
65 return this == other || other instanceof JsonNull;
66 }
67 }
68