Class JsonObject

java.lang.Object
com.cedarsoftware.io.JsonValue
com.cedarsoftware.io.JsonObject
All Implemented Interfaces:
Serializable, Map<Object,Object>

public class JsonObject extends JsonValue implements Map<Object,Object>, Serializable
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:
  • Constructor Details

    • JsonObject

      public JsonObject()
  • Method Details

    • getJsonType

      public JsonObject.JsonType getJsonType()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isMap

      public boolean isMap()
    • isCollection

      public boolean isCollection()
    • isArray

      public boolean isArray()
      Specified by:
      isArray in class JsonValue
    • getItems

      public Object[] getItems()
      Get items array for arrays/collections or @items format. Returns null if setItems() was never called.
    • setItems

      public void setItems(Object[] array)
      Set items directly - for @items format (arrays, collections, maps with @keys).
    • getKeys

      public Object[] getKeys()
      Get keys array for @keys format (maps with non-String keys). Returns null if setKeys() was never called.
    • getTypeString

      public String getTypeString()
    • getItemElementType

      public Type 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

      public void setItemElementType(Type elementType)
      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
      Specified by:
      size in interface Map<Object,Object>
    • getLength

      @Deprecated public int getLength()
      Deprecated.
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<Object,Object>
    • get

      public Object get(Object key)
      Specified by:
      get in interface Map<Object,Object>
    • put

      public Object put(Object key, Object value)
      Specified by:
      put in interface Map<Object,Object>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<Object,Object>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<Object,Object>
    • remove

      public Object remove(Object key)
      Specified by:
      remove in interface Map<Object,Object>
    • putAll

      public void putAll(Map<?,?> map)
      Specified by:
      putAll in interface Map<Object,Object>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<Object,Object>
    • setValue

      public void setValue(Object o)
    • getValue

      public Object getValue()
    • hasValue

      public boolean hasValue()
    • keySet

      public Set<Object> keySet()
      Specified by:
      keySet in interface Map<Object,Object>
    • values

      public Collection<Object> values()
      Specified by:
      values in interface Map<Object,Object>
    • entrySet

      public Set<Map.Entry<Object,Object>> entrySet()
      Specified by:
      entrySet in interface Map<Object,Object>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<Object,Object>
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface Map<Object,Object>
      Overrides:
      equals in class Object
    • setLinearSearchThreshold

      public static void setLinearSearchThreshold(int threshold)
    • getLinearSearchThreshold

      public static int getLinearSearchThreshold()