001/* 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved. 005 * 006 * The contents of this file are subject to the terms of either the GNU 007 * General Public License Version 2 only ("GPL") or the Common Development 008 * and Distribution License("CDDL") (collectively, the "License"). You 009 * may not use this file except in compliance with the License. You can 010 * obtain a copy of the License at 011 * https://oss.oracle.com/licenses/CDDL+GPL-1.1 012 * or LICENSE.txt. See the License for the specific 013 * language governing permissions and limitations under the License. 014 * 015 * When distributing the software, include this License Header Notice in each 016 * file and include the License file at LICENSE.txt. 017 * 018 * GPL Classpath Exception: 019 * Oracle designates this particular file as subject to the "Classpath" 020 * exception as provided by Oracle in the GPL Version 2 section of the License 021 * file that accompanied this code. 022 * 023 * Modifications: 024 * If applicable, add the following below the License Header, with the fields 025 * enclosed by brackets [] replaced by your own identifying information: 026 * "Portions Copyright [year] [name of copyright owner]" 027 * 028 * Contributor(s): 029 * If you wish your version of this file to be governed by only the CDDL or 030 * only the GPL Version 2, indicate your decision by adding "[Contributor] 031 * elects to include this software in this distribution under the [CDDL or GPL 032 * Version 2] license." If you don't indicate a single choice of license, a 033 * recipient has the option to distribute your version of this file under 034 * either the CDDL, the GPL Version 2 or to extend the choice of license to 035 * its licensees as provided above. However, if you add GPL Version 2 code 036 * and therefore, elected the GPL Version 2 license, then the option applies 037 * only if the new code is made subject to such option by the copyright 038 * holder. 039 */ 040 041package javax.json; 042 043/** 044 * <code>JsonValue</code> represents an immutable JSON value. 045 * 046 * <EMBED CLASS='external-html' DATA-FILE-ID=LICENSE DATA-CIETName=JsonValue> 047 * 048 * <BR /><BR />A JSON value is one of the following: 049 * 050 * <BR /><BR /><UL CLASS=JDUL> 051 * <LI>an object ({@link JsonObject})</LI> 052 * <LI>an array ({@link JsonArray})</LI> 053 * <LI>a number ({@link JsonNumber})</LI> 054 * <LI>a string ({@link JsonString})</LI> 055 * <LI>{@code true} ({@link JsonValue#TRUE JsonValue.TRUE})</LI> 056 * <LI>{@code false} ({@link JsonValue#FALSE JsonValue.FALSE})</LI> 057 * <LI>{@code null} ({@link JsonValue#NULL JsonValue.NULL})</LI> 058 * </UL> 059 */ 060public interface JsonValue { 061 062 /** 063 * The empty JSON object. 064 * 065 * @since 1.1 066 */ 067 static final JsonObject EMPTY_JSON_OBJECT = new EmptyObject(); 068 069 /** 070 * The empty JSON array. 071 * 072 * @since 1.1 073 */ 074 static final JsonArray EMPTY_JSON_ARRAY = new EmptyArray(); 075 076 /** 077 * Indicates the type of a {@link JsonValue} object. 078 */ 079 enum ValueType { 080 /** 081 * JSON array. 082 */ 083 ARRAY, 084 085 /** 086 * JSON object. 087 */ 088 OBJECT, 089 090 /** 091 * JSON string. 092 */ 093 STRING, 094 095 /** 096 * JSON number. 097 */ 098 NUMBER, 099 100 /** 101 * JSON true. 102 */ 103 TRUE, 104 105 /** 106 * JSON false. 107 */ 108 FALSE, 109 110 /** 111 * JSON null. 112 */ 113 NULL 114 } 115 116 /** 117 * JSON null value. 118 */ 119 static final JsonValue NULL = new JsonValueImpl(ValueType.NULL); 120 121 /** 122 * JSON true value. 123 */ 124 static final JsonValue TRUE = new JsonValueImpl(ValueType.TRUE); 125 126 /** 127 * JSON false value. 128 */ 129 static final JsonValue FALSE = new JsonValueImpl(ValueType.FALSE); 130 131 /** 132 * Returns the value type of this JSON value. 133 * 134 * @return JSON value type 135 */ 136 ValueType getValueType(); 137 138 /** 139 * Return the JsonValue as a JsonObject 140 * 141 * @return the JsonValue as a JsonObject 142 * @throws ClassCastException if the JsonValue is not a JsonObject 143 * 144 * @since 1.1 145 */ 146 default JsonObject asJsonObject() { 147 return JsonObject.class.cast(this); 148 } 149 150 /** 151 * Return the JsonValue as a JsonArray 152 * 153 * @return the JsonValue as a JsonArray 154 * @throws ClassCastException if the JsonValue is not a JsonArray 155 * 156 * @since 1.1 157 */ 158 default JsonArray asJsonArray() { 159 return JsonArray.class.cast(this); 160 } 161 162 /** 163 * Returns JSON text for this JSON value. 164 * 165 * @return JSON text 166 */ 167 @Override 168 String toString(); 169 170}