Package com.cedarsoftware.io
Class JsonObject
java.lang.Object
com.cedarsoftware.io.JsonValue
com.cedarsoftware.io.JsonObject
- All Implemented Interfaces:
Serializable,Map<Object,Object>
This class holds a JSON object using parallel arrays for memory efficiency
and insertion-order preservation. Instances of this class hold a Map-of-Map
representation of a Java object, read from the JSON input stream.
Storage design:
- Parallel arrays (keys[], values[]) for map entries (POJOs, maps with String keys)
- Separate items[] array for @items content (arrays, collections)
- For @keys/@items format maps: keys[] holds complex keys, items[] holds values
- Lazy HashMap index built only when needed for O(1) lookup on large objects
- Author:
- John DeRegnaucourt (jdereg@gmail.com)
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
License
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumType classification for optimized dispatch in Resolver. -
Field Summary
Fields inherited from class com.cedarsoftware.io.JsonValue
ENUM, id, ID, isFinished, ITEMS, JSON5_ID, JSON5_ITEMS, JSON5_KEYS, JSON5_REF, JSON5_SHORT_ID, JSON5_SHORT_ITEMS, JSON5_SHORT_KEYS, JSON5_SHORT_REF, JSON5_SHORT_TYPE, JSON5_TYPE, KEYS, REF, refId, SHORT_ID, SHORT_ITEMS, SHORT_KEYS, SHORT_REF, SHORT_TYPE, target, TYPE, VALUE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()booleanGet the stored element type for collections/arrays (or value type for maps).Object[]getItems()Get items array for arrays/collections or @items format.Object[]getKeys()Get keys array for @keys format (maps with non-String keys).intDeprecated.static intgetValue()inthashCode()booleanhasValue()booleanisArray()booleanbooleanisEmpty()booleanisMap()keySet()voidvoidsetItemElementType(Type elementType) Set the element type for collections/arrays (or value type for maps).voidSet items directly - for @items format (arrays, collections, maps with @keys).static voidsetLinearSearchThreshold(int threshold) voidintsize()Returns the effective size for Map operations.toString()values()Methods inherited from class com.cedarsoftware.io.JsonValue
clearTypeResolutionCache, getId, getJavaType, getMaxTypeResolutionCacheSize, getRawType, getRawTypeName, getReferenceId, getTarget, getType, getTypeResolutionCacheSize, hasId, isFinished, isReference, setFinished, setFinishedTarget, setId, setJavaType, setMaxTypeResolutionCacheSize, setReferenceId, setTarget, setTypeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
JsonObject
public JsonObject()
-
-
Method Details
-
getJsonType
-
toString
-
isMap
public boolean isMap() -
isCollection
public boolean isCollection() -
isArray
public boolean isArray() -
getItems
Get items array for arrays/collections or @items format. Returns null if setItems() was never called. -
setItems
Set items directly - for @items format (arrays, collections, maps with @keys). -
getKeys
Get keys array for @keys format (maps with non-String keys). Returns null if setKeys() was never called. -
getTypeString
-
getItemElementType
Get the stored element type for collections/arrays (or value type for maps). This preserves generic type information that would otherwise be lost when the type is changed to a concrete class during instance creation.- Returns:
- the element/value type, or null if not set
-
setItemElementType
Set the element type for collections/arrays (or value type for maps). Should be called before createInstance to preserve generic type information.- Parameters:
elementType- the element/value type from the ParameterizedType
-
size
public int size()Returns the effective size for Map operations. For @keys/@items format (both set): number of key-value pairs For @keys only (incomplete): 0 For POJOs: number of field entries -
getLength
Deprecated. -
isEmpty
public boolean isEmpty() -
get
-
put
-
containsKey
- Specified by:
containsKeyin interfaceMap<Object,Object>
-
containsValue
- Specified by:
containsValuein interfaceMap<Object,Object>
-
remove
-
putAll
-
clear
public void clear() -
setValue
-
getValue
-
hasValue
public boolean hasValue() -
keySet
-
values
-
entrySet
-
hashCode
public int hashCode() -
equals
-
setLinearSearchThreshold
public static void setLinearSearchThreshold(int threshold) -
getLinearSearchThreshold
public static int getLinearSearchThreshold()
-