Share via


JacksonJsonObject Class

public final class JacksonJsonObject
extends 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

Constructor Description
JacksonJsonObject()

Creates a new JacksonJsonObject using the default JsonNodeFactory#instance ObjectNode.

JacksonJsonObject(ObjectNode object)

Creates a new JacksonJsonObject using the provided ObjectNode.

Method Summary

Modifier and Type Method and Description
static JacksonJsonObject fromJson(JsonReader jsonReader)

Deserializes a JSON object from a JsonReader.

com.fasterxml.jackson.databind.JsonNode getProperty(String key)

Gets the JsonNode value corresponding to the specified key.

boolean isObject()
com.fasterxml.jackson.databind.JsonNode removeProperty(String key)

Removes the JsonNode value corresponding to the specified key.

JacksonJsonObject setProperty(String key, JsonNode node)

Sets the JsonNode value corresponding to the specified key.

int size()

The number of properties in the JSON object.

JsonWriter toJson(JsonWriter jsonWriter)

Methods inherited from JsonElement

Methods inherited from java.lang.Object

Constructor Details

JacksonJsonObject

public JacksonJsonObject()

Creates a new JacksonJsonObject using the default JsonNodeFactory#instance ObjectNode.

JacksonJsonObject

public JacksonJsonObject(ObjectNode object)

Creates a new JacksonJsonObject using the provided ObjectNode.

Parameters:

object - The ObjectNode to use as the backing object.

Method Details

fromJson

public static JacksonJsonObject fromJson(JsonReader jsonReader)

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.

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.

isObject

public boolean isObject()

Overrides:

JacksonJsonObject.isObject()

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.

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.

size

public int size()

The number of properties in the JSON object.

Returns:

The number of properties in the JSON object.

toJson

public JsonWriter toJson(JsonWriter jsonWriter)

Parameters:

jsonWriter

Throws:

Applies to