001/* 002 * Copyright 2015-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2015-2020 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2015-2020 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.util.json; 037 038 039 040import com.unboundid.util.NotMutable; 041import com.unboundid.util.ThreadSafety; 042import com.unboundid.util.ThreadSafetyLevel; 043 044 045 046/** 047 * This class provides an implementation of a JSON value that represents a null 048 * value. The string representation of the null value is {@code null} in all 049 * lowercase and without any quotation marks. 050 */ 051@NotMutable() 052@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 053public final class JSONNull 054 extends JSONValue 055{ 056 /** 057 * A pre-allocated JSON null value object. 058 */ 059 public static final JSONNull NULL = new JSONNull(); 060 061 062 063 /** 064 * The serial version UID for this serializable class. 065 */ 066 private static final long serialVersionUID = -8359265286375144526L; 067 068 069 070 /** 071 * Creates a new JSON value capable of representing a {@code null} value. 072 */ 073 public JSONNull() 074 { 075 } 076 077 078 079 /** 080 * {@inheritDoc} 081 */ 082 @Override() 083 public int hashCode() 084 { 085 return 1; 086 } 087 088 089 090 /** 091 * {@inheritDoc} 092 */ 093 @Override() 094 public boolean equals(final Object o) 095 { 096 return ((o == this) || (o instanceof JSONNull)); 097 } 098 099 100 101 /** 102 * {@inheritDoc} 103 */ 104 @Override() 105 public boolean equals(final JSONValue v, final boolean ignoreFieldNameCase, 106 final boolean ignoreValueCase, 107 final boolean ignoreArrayOrder) 108 { 109 return (v instanceof JSONNull); 110 } 111 112 113 114 /** 115 * Retrieves a string representation of this null value as it should appear 116 * in a JSON object. Null values will always have a string representation of 117 * "{@code null}" (without the surrounding quotes). 118 * 119 * @return A string representation of this null value as it should appear 120 * in a JSON object. 121 */ 122 @Override() 123 public String toString() 124 { 125 return "null"; 126 } 127 128 129 130 /** 131 * Appends a string representation of this null value as it should appear 132 * in a JSON object to the provided buffer. Null values will always have a 133 * string representation of "{@code null}" (without the surrounding quotes). 134 * 135 * @param buffer The buffer to which the information should be appended. 136 */ 137 @Override() 138 public void toString(final StringBuilder buffer) 139 { 140 buffer.append("null"); 141 } 142 143 144 145 /** 146 * Retrieves a single-line string representation of this null value as it 147 * should appear in a JSON object. Null values will always have a string 148 * representation of "{@code null}" (without the surrounding quotes). 149 * 150 * @return A single-line string representation of this null value as it 151 * should appear in a JSON object. 152 */ 153 @Override() 154 public String toSingleLineString() 155 { 156 return "null"; 157 } 158 159 160 161 /** 162 * Appends a single-line string representation of this null value as it should 163 * appear in a JSON object to the provided buffer. Null values will always 164 * have a string representation of "{@code null}" (without the surrounding 165 * quotes). 166 * 167 * @param buffer The buffer to which the information should be appended. 168 */ 169 @Override() 170 public void toSingleLineString(final StringBuilder buffer) 171 { 172 buffer.append("null"); 173 } 174 175 176 177 /** 178 * Retrieves a normalized string representation of this null value as it 179 * should appear in a JSON object. Null values will always have a string 180 * representation of "{@code null}" (without the surrounding quotes). 181 * 182 * @return A normalized string representation of this null value as it 183 * should appear in a JSON object. 184 */ 185 @Override() 186 public String toNormalizedString() 187 { 188 return "null"; 189 } 190 191 192 193 /** 194 * Appends a normalized string representation of this null value as it should 195 * appear in a JSON object to the provided buffer. Null values will always 196 * have a string representation of "{@code null}" (without the surrounding 197 * quotes). 198 * 199 * @param buffer The buffer to which the information should be appended. 200 */ 201 @Override() 202 public void toNormalizedString(final StringBuilder buffer) 203 { 204 buffer.append("null"); 205 } 206 207 208 209 /** 210 * Retrieves a normalized string representation of this null value as it 211 * should appear in a JSON object. Null values will always have a string 212 * representation of "{@code null}" (without the surrounding quotes). 213 * 214 * @param ignoreFieldNameCase Indicates whether field names should be 215 * treated in a case-sensitive (if {@code false}) 216 * or case-insensitive (if {@code true}) manner. 217 * @param ignoreValueCase Indicates whether string field values should 218 * be treated in a case-sensitive (if 219 * {@code false}) or case-insensitive (if 220 * {@code true}) manner. 221 * @param ignoreArrayOrder Indicates whether the order of elements in an 222 * array should be considered significant (if 223 * {@code false}) or insignificant (if 224 * {@code true}). 225 * 226 * @return A normalized string representation of this null value as it 227 * should appear in a JSON object. 228 */ 229 @Override() 230 public String toNormalizedString(final boolean ignoreFieldNameCase, 231 final boolean ignoreValueCase, 232 final boolean ignoreArrayOrder) 233 { 234 return "null"; 235 } 236 237 238 239 /** 240 * Appends a normalized string representation of this null value as it should 241 * appear in a JSON object to the provided buffer. Null values will always 242 * have a string representation of "{@code null}" (without the surrounding 243 * quotes). 244 * 245 * @param buffer The buffer to which the information should be 246 * appended. 247 * @param ignoreFieldNameCase Indicates whether field names should be 248 * treated in a case-sensitive (if {@code false}) 249 * or case-insensitive (if {@code true}) manner. 250 * @param ignoreValueCase Indicates whether string field values should 251 * be treated in a case-sensitive (if 252 * {@code false}) or case-insensitive (if 253 * {@code true}) manner. 254 * @param ignoreArrayOrder Indicates whether the order of elements in an 255 * array should be considered significant (if 256 * {@code false}) or insignificant (if 257 * {@code true}). 258 */ 259 @Override() 260 public void toNormalizedString(final StringBuilder buffer, 261 final boolean ignoreFieldNameCase, 262 final boolean ignoreValueCase, 263 final boolean ignoreArrayOrder) 264 { 265 buffer.append("null"); 266 } 267 268 269 270 /** 271 * {@inheritDoc} 272 */ 273 @Override() 274 public void appendToJSONBuffer(final JSONBuffer buffer) 275 { 276 buffer.appendNull(); 277 } 278 279 280 281 /** 282 * {@inheritDoc} 283 */ 284 @Override() 285 public void appendToJSONBuffer(final String fieldName, 286 final JSONBuffer buffer) 287 { 288 buffer.appendNull(fieldName); 289 } 290}