001/*
002 * Copyright 2026 Revetware LLC.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.revetsec.json;
018
019import com.revetsec.internal.json.JsonWriter;
020import org.jspecify.annotations.NonNull;
021import org.jspecify.annotations.Nullable;
022
023import javax.annotation.concurrent.Immutable;
024
025/**
026 * The JSON {@code null}. It is a value, distinct from an absent member: {@code {"a":null}} has a member {@code a},
027 * and {@code {}} has none.
028 * <p>
029 * This is a final class with one shared instance, not an enum, so it has no {@code values()}, {@code ordinal()} or
030 * {@code name()}.
031 *
032 * @author <a href="https://www.revetkn.com">Mark Allen</a>
033 * @since 1.0.0
034 */
035@Immutable
036public final class JsonNull implements JsonValue {
037        @NonNull
038        private static final JsonNull INSTANCE = new JsonNull();
039
040        /**
041         * Returns the JSON {@code null}.
042         *
043         * @return the shared instance
044         * @since 1.0.0
045         */
046        @NonNull
047        public static JsonNull defaultInstance() {
048                return INSTANCE;
049        }
050
051        private JsonNull() {
052        }
053
054        @Override
055        @NonNull
056        public String toJson() {
057                return JsonWriter.toJson(this);
058        }
059
060        @Override
061        public boolean equals(@Nullable Object other) {
062                return other instanceof JsonNull;
063        }
064
065        @Override
066        public int hashCode() {
067                return 0x6E756C6C;
068        }
069
070        @Override
071        @NonNull
072        public String toString() {
073                return "JsonNull{value=<redacted>}";
074        }
075}