Class JacksonJsonArray

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

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

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

  • Constructor Details

  • Method Details

    • isArray

      public boolean isArray()
      Overrides:
      isArray in class com.azure.json.models.JsonElement
    • addElement

      public JacksonJsonArray addElement(JsonNode node)
      Adds a JsonNode to the JSON array. This node will be appended to the end of the array.
      Parameters:
      node - The JsonNode to add to the array.
      Returns:
      The updated JacksonJsonArray object.
      Throws:
      NullPointerException - If the node is null.
    • addElement

      public JacksonJsonArray addElement(int index, JsonNode node)
      Adds a JsonNode to the JSON array at the specified index. This node will be inserted at the specified index and all elements at or after the index will be shifted.
      Parameters:
      index - The index at which to add the node.
      node - The JsonNode to add to the array.
      Returns:
      The updated JacksonJsonArray object.
      Throws:
      NullPointerException - If the node is null.
      IndexOutOfBoundsException - If the index is less than zero or greater than or equal to size().
    • setElement

      public JacksonJsonArray setElement(int index, JsonNode node)
      Sets a specified JsonNode object at a specified index within the JacksonJsonArray. This will replace the current JsonNode at the specified index with the newly specified JsonNode object.
      Parameters:
      index - The index at which to set the node.
      node - The JsonNode to set at the specified index.
      Returns:
      The updated JacksonJsonArray object.
      Throws:
      NullPointerException - If the node is null.
      IndexOutOfBoundsException - If the index is less than zero or greater than or equal to size().
    • getElement

      public JsonNode getElement(int index) throws IndexOutOfBoundsException
      Gets the JsonNode at the specified index from the JacksonJsonArray.
      Parameters:
      index - The index at which to get the element.
      Returns:
      The JsonNode at the specified index.
      Throws:
      IndexOutOfBoundsException - If the index is less than zero or greater than or equal to size().
    • removeElement

      public JsonNode removeElement(int index) throws IndexOutOfBoundsException
      Removes the JsonNode at the specified index from the JacksonJsonArray. This will shift all elements after the specified index.
      Parameters:
      index - The index at which to remove the element.
      Returns:
      The removed JsonNode.
      Throws:
      IndexOutOfBoundsException - If the index is less than zero or greater than or equal to size().
    • size

      public int size()
      The number of elements in the JacksonJsonArray.
      Returns:
      The number of elements in the JacksonJsonArray.
    • toJson

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

      public static JacksonJsonArray fromJson(com.azure.json.JsonReader jsonReader) throws IOException
      Deserializes a JSON array 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_ARRAY, an IllegalStateException will be thrown. Otherwise, a JSON array representing the array will be created and returned.

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