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 Summary
ConstructorsConstructorDescriptionJacksonJsonObject(ObjectNode object) Creates a newJacksonJsonObjectusing the providedObjectNode. -
Method Summary
Modifier and TypeMethodDescriptionstatic JacksonJsonObjectfromJson(com.azure.json.JsonReader jsonReader) Deserializes a JSON object from a JsonReader.getProperty(String key) Gets the JsonNode value corresponding to the specified key.booleanisObject()removeProperty(String key) Removes the JsonNode value corresponding to the specified key.setProperty(String key, JsonNode node) Sets the JsonNode value corresponding to the specified key.intsize()The number of properties in the JSON object.com.azure.json.JsonWritertoJson(com.azure.json.JsonWriter jsonWriter) Methods inherited from class com.azure.json.models.JsonElement
asArray, asBoolean, asNull, asNumber, asObject, asString, isArray, isBoolean, isNull, isNumber, 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
-
JacksonJsonObject
public JacksonJsonObject() -
JacksonJsonObject
Creates a newJacksonJsonObjectusing the providedObjectNode.- Parameters:
object- TheObjectNodeto use as the backing object.- Throws:
NullPointerException- Ifobjectis null.
-
-
Method Details
-
getProperty
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
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 thekeyornodeis null.
-
removeProperty
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 thekeyis 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:
isObjectin classcom.azure.json.models.JsonElement
-
toJson
- Throws:
IOException
-
fromJson
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, anIllegalStateExceptionwill 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 notJsonToken.START_OBJECT.
-