Class JacksonJsonObject

java.lang.Object
com.azure.json.models.JsonElement
com.azure.core.serializer.json.jackson.models.JacksonJsonObject
All Implemented Interfaces:
com.azure.json.JsonSerializable<com.azure.json.models.JsonElement>

public final class JacksonJsonObject extends com.azure.json.models.JsonElement
Implementation of JsonElement which is backed by Jackson's ObjectNode.

This allows for using Jackson's ObjectNode in places where JsonObject is required, meaning the Jackson ObjectNode doesn't need to be converted to azure-json's JsonObject.

  • Constructor Details

  • Method Details

    • getProperty

      public JsonNode getProperty(String key)
      Gets the JsonNode value corresponding to the specified key. If the key doesn't exist, null will be returned.
      Parameters:
      key - The key of the property to get.
      Returns:
      The JsonNode value corresponding to the specified key, or null if the property doesn't exist.
    • setProperty

      public JacksonJsonObject setProperty(String key, JsonNode node)
      Sets the JsonNode value corresponding to the specified key. If the key already exists, the value will be overwritten.
      Parameters:
      key - The key of the property to set.
      node - The JsonNode value to set the property to.
      Returns:
      The updated JacksonJsonObject object.
      Throws:
      NullPointerException - If the key or node is null.
    • removeProperty

      public JsonNode removeProperty(String key)
      Removes the JsonNode value corresponding to the specified key. If the key doesn't exist, null will be returned.
      Parameters:
      key - The key of the property to remove.
      Returns:
      The JsonNode value corresponding to the specified key, or null if the property doesn't exist.
      Throws:
      NullPointerException - If the key is null.
    • size

      public int size()
      The number of properties in the JSON object.
      Returns:
      The number of properties in the JSON object.
    • isObject

      public boolean isObject()
      Overrides:
      isObject in class com.azure.json.models.JsonElement
    • toJson

      public com.azure.json.JsonWriter toJson(com.azure.json.JsonWriter jsonWriter) throws IOException
      Throws:
      IOException
    • fromJson

      public static JacksonJsonObject fromJson(com.azure.json.JsonReader jsonReader) throws IOException
      Deserializes a JSON object from a JsonReader.

      If the JsonReader's current token is null, it is assumed the JsonReader hasn't begun reading and JsonReader.nextToken() will be called to begin reading.

      After ensuring the JsonReader has begun reading, if the current token is not JsonToken.START_OBJECT, an IllegalStateException will be thrown. Otherwise, a JSON object representing the object will be created and returned.

      Parameters:
      jsonReader - The JsonReader to deserialize from.
      Returns:
      The deserialized JSON object.
      Throws:
      IOException - If an error occurs while deserializing the JSON object.
      IllegalStateException - If the current token is not JsonToken.START_OBJECT.