Interface OracleJsonObject

  • All Superinterfaces:
    Map<String,​OracleJsonValue>, OracleJsonStructure, OracleJsonValue

    public interface OracleJsonObject
    extends OracleJsonStructure, Map<String,​OracleJsonValue>
    A JSON object (an unordered collection of zero or more key/value pairs). The object may contain any subtype of OracleJsonValue which includes the extended SQL types such as OracleJsonTimestamp.

    Instances of OracleJsonObject may either be mutable or immutable. When an instance is immutable, calling methods that would mutate the object will throw UnsupportedOperationException. For example, OracleJsonObject instances that are returned from a ResultSet are immutable. Instances that are returned from OracleJsonFactory.createObject() and OracleJsonFactory.createObject(OracleJsonObject) methods are mutable.

    Example:
    
      import oracle.sql.json.OracleJsonFactory;
      import oracle.sql.json.OracleJsonObject;
      
      public class JsonObjectExample {
        public static void main(String[] args) {
          OracleJsonFactory factory = new OracleJsonFactory();
          OracleJsonObject obj = factory.createObject();
          obj.put("name", "orange");
          obj.put("count", 12); 
          System.out.println(obj.toString());
          System.out.println(obj.getString("name"));
        }
      }

    Running this example prints:

      {"name":"orange","count":12}
      orange
      
    • Method Detail

      • getString

        String getString​(String key)
        Returns the string to which the specified key is mapped. This is a convenience method that is equivalent to get(key).asJsonString().getString().
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        ClassCastException - if the value to which the specified key is mapped is not an instance of OracleJsonString.
        NullPointerException - if the specified key does not have a mapping
      • getInt

        int getInt​(String key)
        Returns the integer to which the specified key is mapped. This is a convenience method that is equivalent to ((OracleJsonNumber)get(key)).intValue().
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        ClassCastException - if the value to which the specified key is mapped is not an instance of OracleJsonNumber.
        NullPointerException - if the specified key does not have a mapping
      • getDouble

        double getDouble​(String key)
        Returns the double to which the specified key is mapped. This is a convenience method that is equivalent to ((OracleJsonNumber)get(key)).doubleValue().
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        ClassCastException - if the value to which the specified key is mapped is not an instance of OracleJsonNumber.
        NullPointerException - if the specified key does not have a mapping
      • getLong

        long getLong​(String key)
        Returns the long to which the specified key is mapped. This is a convenience method that is equivalent to ((OracleJsonNumber)get(key)).longValue().
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        ClassCastException - if the value to which the specified key is mapped is not an instance of OracleJsonNumber.
        NullPointerException - if the specified key does not have a mapping
      • getBigDecimal

        BigDecimal getBigDecimal​(String key)
        Returns the decimal to which the specified key is mapped. This is a convenience method that is equivalent to ((OracleJsonNumber)get(key)).bigDecimalValue().
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        ClassCastException - if the value to which the specified key is mapped is not an instance of OracleJsonNumber.
        NullPointerException - if the specified key does not have a mapping
      • getBoolean

        boolean getBoolean​(String key)
        Returns the boolean to which the specified key is mapped. Specifically, returns true if the mapped value is equal to OracleJsonValue.TRUE and false if the value at the mapped value is equal to OracleJsonValue.FALSE.
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        ClassCastException - if the value to which the specified key is mapped is not equal to OracleJsonValue.TRUE or OracleJsonValue.FALSE
        NullPointerException - if the specified key does not have a mapping
      • isNull

        boolean isNull​(String key)
        Returns true if the specified key is mapped to a value equal to OracleJsonValue.NULL.
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        NullPointerException - if the specified key does not have a mapping
      • getLocalDateTime

        java.time.LocalDateTime getLocalDateTime​(String key)
        Returns the value to which the specified key is mapped. This is a convenience method that is equivalent to get(key).asJsonDate().getLocalDateTime() or get(key).asJsonTimestamp().getLocalDateTime() depending if the value is a date or a timestamp.
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        ClassCastException - if the value to which the specified key is mapped is not an instance of OracleJsonDate or OracleJsonTimestamp.
        NullPointerException - if the specified key does not have a mapping
      • getOffsetDateTime

        java.time.OffsetDateTime getOffsetDateTime​(String key)
        Returns the value to which the specified key is mapped. This is a convenience method that is equivalent to get(key).asJsonTimestampTZ().getOffsetDateTime().
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        ClassCastException - if the value to which the specified key is mapped is not an instance of OracleJsonTimestampTZ.
        NullPointerException - if the specified key does not have a mapping
      • getBytes

        byte[] getBytes​(String key)
        Returns the binary value to which the specified key is mapped. This is a convenience method that is equivalent to get(key).asJsonBinary().getBytes()
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped
        Throws:
        ClassCastException - if the value to which the specified key is mapped is not an instance of OracleJsonBinary.
        NullPointerException - if the specified key does not have a mapping
      • getString

        String getString​(String key,
                         String defaultValue)
        Returns the string to which the specified key is mapped. If an instance of OracleJsonString is mapped to the key, then the result of calling getString() on the instance is returned. Otherwise, the specified defaultValue is returned.
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - a default value to return
        Returns:
        the value to which the specified key is mapped or the default value
      • getInt

        int getInt​(String key,
                   int defaultValue)
        Returns the integer to which the specified key is mapped. If an instance of OracleJsonNumber is mapped to the key, then the result of calling intValue() the instance is returned. Otherwise, the specified defaultValue is returned.
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - a default value to return
        Returns:
        the value to which the specified key is mapped or the default value
      • getDouble

        double getDouble​(String key,
                         double defaultValue)
        Returns the double to which the specified key is mapped. If an instance of OracleJsonNumber is mapped to the key, then the result of calling doubleValue() the instance is returned. Otherwise, the specified defaultValue is returned.
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - a default value to return
        Returns:
        the value to which the specified key is mapped or the default value
      • getLong

        long getLong​(String key,
                     long defaultValue)
        Returns the long to which the specified key is mapped. If an instance of OracleJsonNumber is mapped to the key, then the result of calling longValue() the instance is returned. Otherwise, the specified defaultValue is returned.
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - a default value to return
        Returns:
        the value to which the specified key is mapped or the default value
      • getBigDecimal

        BigDecimal getBigDecimal​(String key,
                                 BigDecimal defaultValue)
        Returns the long to which the specified key is mapped. If an instance of OracleJsonNumber is mapped to the key, then the result of calling bigDecimalValue() the instance is returned. Otherwise, the specified defaultValue is returned.
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - a default value to return
        Returns:
        the value to which the specified key is mapped or the default value
      • getBoolean

        boolean getBoolean​(String key,
                           boolean defaultValue)
        Returns the boolean to which the specified key is mapped. If the mapped value is equal to OracleJsonValue.TRUE then true is returned. If the mapped value is equal to OracleJsonValue.FALSE then false is returned. Otherwise, the specified defaultValue is returned.
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - a default value to return
        Returns:
        the value to which the specified key is mapped or the default value
      • getLocalDateTime

        java.time.LocalDateTime getLocalDateTime​(String key,
                                                 java.time.LocalDateTime defaultValue)
        Returns the value to which the specified key is mapped. If the mapped value is a date or a timestamp, then the result of calling getLocalDateTime() on the value is returned. Otherwise, the specified defaultValue is returned.
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - a default value to return
        Returns:
        the value to which the specified key is mapped or the default value
      • getOffsetDateTime

        java.time.OffsetDateTime getOffsetDateTime​(String key,
                                                   java.time.OffsetDateTime defaultValue)
        Returns the value to which the specified key is mapped. If the mapped value is an instance of OracleTimestampTZ, then the result of calling getOffsetDateTime() on the value is returned.
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - a default value to return
        Returns:
        the value to which the specified key is mapped or the default value
      • getBytes

        byte[] getBytes​(String key,
                        byte[] defaultValue)
        Returns the binary value to which the specified key is mapped. If an instance of OracleJsonBinary is mapped to the key, then the result of calling getBytes() on the instance is returned. Otherwise, the specified defaultValue is returned.
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - a default value to return
        Returns:
        the value to which the specified key is mapped or the default value
      • put

        OracleJsonValue put​(String key,
                            String value)
        Associates the specified string value with the specified key. The string is added to the object as an instance of OracleJsonString. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the specified value is to be associated
        value - the value to be associated with the specified key
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported
      • put

        OracleJsonValue put​(String key,
                            int value)
        Associates the specified integer value with the specified key. The integer is added to the object as an instance of OracleJsonDecimal. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the specified value is to be associated
        value - the value to be associated with the specified key
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported
      • put

        OracleJsonValue put​(String key,
                            long value)
        Associates the specified long value with the specified key. The long is added to the object as an instance of OracleJsonDecimal. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the specified value is to be associated
        value - the value to be associated with the specified key
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported
      • put

        OracleJsonValue put​(String key,
                            BigDecimal value)
                     throws OracleJsonException
        Associates the specified decimal value with the specified key. The decimal is added to the object as an instance of OracleJsonDecimal. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the specified value is to be associated
        value - the value to be associated with the specified key
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported
        OracleJsonException
      • put

        OracleJsonValue put​(String key,
                            double value)
        Associates the specified double value with the specified key. The double is added to the object as an instance of OracleJsonDouble. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the specified value is to be associated
        value - the value to be associated with the specified key
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported
      • put

        OracleJsonValue put​(String key,
                            boolean value)
        Associates the specified boolean value with the specified key. If the value is true, OracleJsonValue.TRUE is associated with the key and if it is false then OracleJsonValue.FALSE is associated with the key. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the specified value is to be associated
        value - the value to be associated with the specified key
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported
      • putNull

        OracleJsonValue putNull​(String key)
        Associates the OracleJsonValue.NULL with the specified key. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the OracleJsonValue.NULL value is to be associated
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported
      • put

        OracleJsonValue put​(String key,
                            java.time.LocalDateTime value)
        Associates the specified value with the specified key. The value is added to the object as an instance of OracleJsonTimestamp. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the specified value is to be associated
        value - the value to be associated with the specified key
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported
      • put

        OracleJsonValue put​(String key,
                            java.time.OffsetDateTime value)
        Associates the specified value with the specified key. The value is added to the object as an instance of OracleJsonTimestampTZ. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the specified value is to be associated
        value - the value to be associated with the specified key
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported
      • put

        OracleJsonValue put​(String key,
                            byte[] values)
        Associates the specified binary value with the specified key. The binary value is added to the object as an instance of OracleJsonBinary. If the object previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - the key with which the specified value is to be associated
        value - the value to be associated with the specified key
        Returns:
        the previous value associated with the key, or null if there was no mapping for key.
        Throws:
        UnsupportedOperationException - if the put operation is not supported