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
-
Constructor Summary
ConstructorsConstructorDescriptionJacksonJsonArray(ArrayNode array) Creates a newJacksonJsonArrayusing the providedArrayNode. -
Method Summary
Modifier and TypeMethodDescriptionaddElement(int index, JsonNode node) Adds a JsonNode to the JSON array at the specified index.addElement(JsonNode node) Adds a JsonNode to the JSON array.static JacksonJsonArrayfromJson(com.azure.json.JsonReader jsonReader) Deserializes a JSON array from a JsonReader.getElement(int index) Gets the JsonNode at the specified index from the JacksonJsonArray.booleanisArray()removeElement(int index) Removes the JsonNode at the specified index from the JacksonJsonArray.setElement(int index, JsonNode node) Sets a specified JsonNode object at a specified index within the JacksonJsonArray.intsize()The number of elements in the JacksonJsonArray.com.azure.json.JsonWritertoJson(com.azure.json.JsonWriter jsonWriter) Methods inherited from class com.azure.json.models.JsonElement
asArray, asBoolean, asNull, asNumber, asObject, asString, isBoolean, isNull, isNumber, isObject, isStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.azure.json.JsonSerializable
toJson, toJson, toJsonBytes, toJsonString
-
Constructor Details
-
JacksonJsonArray
public JacksonJsonArray() -
JacksonJsonArray
Creates a newJacksonJsonArrayusing the providedArrayNode.- Parameters:
array- TheArrayNodeto use as the backing array.- Throws:
NullPointerException- Ifarrayis null.
-
-
Method Details
-
isArray
public boolean isArray()- Overrides:
isArrayin classcom.azure.json.models.JsonElement
-
addElement
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 thenodeis null.
-
addElement
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 thenodeis null.IndexOutOfBoundsException- If theindexis less than zero or greater than or equal tosize().
-
setElement
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 thenodeis null.IndexOutOfBoundsException- If theindexis less than zero or greater than or equal tosize().
-
getElement
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 theindexis less than zero or greater than or equal tosize().
-
removeElement
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 theindexis less than zero or greater than or equal tosize().
-
size
public int size()The number of elements in the JacksonJsonArray.- Returns:
- The number of elements in the JacksonJsonArray.
-
toJson
- Throws:
IOException
-
fromJson
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, anIllegalStateExceptionwill 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 notJsonToken.START_ARRAY.
-