JsonSerializable Class

  • java.lang.Object
    • com.microsoft.azure.documentdb.JsonSerializable

Implements

java.io.Serializable

public class JsonSerializable
implements java.io.Serializable

Represents a base resource that can be serialized to JSON in the Azure Cosmos DB database service. Note on Serializable: this interface is implemented solely for the use with the CosmosDB Spark Connector. In RDD transformation, it is a requirement of the RDD item type to be Serializable so that they can be transferred among the work nodes by the default serializer. The Serializable is not intended to be used by the user of the Cosmos DB Java SDK. Avoid relying on the serialized string format as it can change in the future.

Constructor Summary

Modifier Constructor Description
protected JsonSerializable()
protected JsonSerializable(String jsonString)

Constructor.

protected JsonSerializable(String jsonString, ObjectMapper objectMapper)

Constructor.

protected JsonSerializable(JSONObject jsonObject)

Constructor.

Method Summary

Modifier and Type Method and Description
java.util.Collection<T> getCollection(String propertyName, Class<T> c)

Gets an object collection.

T getObject(String propertyName, Class<T> c)

Gets an object value.

void set(String propertyName, T value)

Sets the value of a property.

T toObject(Class<T> c)

Converts to an Object (only POJOs and JSONObject are supported).

java.lang.Object get(String propertyName)

Gets a property value as Object.

java.lang.Boolean getBoolean(String propertyName)

Gets a boolean value.

java.util.Collection<org.json.JSONObject> getCollection(String propertyName)

Gets a JSONObject collection.

java.lang.Double getDouble(String propertyName)

Gets a double value.

java.util.HashMap<java.lang.String,java.lang.Object> getHashMap()

Returns the propertybag(JSONObject) in a hashMap

java.lang.Integer getInt(String propertyName)

Gets an integer value.

protected org.slf4j.Logger getLogger()
java.lang.Long getLong(String propertyName)

Gets a long value.

protected com.fasterxml.jackson.databind.ObjectMapper getMapper()
org.json.JSONObject getObject(String propertyName)

Gets a JSONObject.

java.lang.Object getObjectByPath(Collection<String> propertyNames)

Gets the value of a property identified by an array of property names that forms the path.

java.lang.String getString(String propertyName)

Gets a string value.

boolean has(String propertyName)

Checks whether a property exists.

void remove(String propertyName)

Removes a value by propertyName.

java.lang.String toJson()

Converts to a JSON string.

java.lang.String toJson(SerializationFormattingPolicy formattingPolicy)

Converts to a JSON string.

java.lang.String toString()

Gets Simple String representation of property bag.

java.lang.String toString(int indentFactor)

Deprecated

For proper conversion to json and inclusion of the default values use toJson(SerializationFormattingPolicy formattingPolicy).

Gets formatted String representation of property bag.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

JsonSerializable

protected JsonSerializable()

JsonSerializable

protected JsonSerializable(String jsonString)

Constructor.

Parameters:

jsonString - the json string that represents the JsonSerializable.

JsonSerializable

protected JsonSerializable(String jsonString, ObjectMapper objectMapper)

Constructor.

Parameters:

jsonString - the json string that represents the JsonSerializable.
objectMapper - the custom object mapper

JsonSerializable

protected JsonSerializable(JSONObject jsonObject)

Constructor.

Parameters:

jsonObject - the json object that represents the JsonSerializable.

Method Details

getCollection

public Collection getCollection(String propertyName, Class c)

Gets an object collection.

Parameters:

propertyName - the property to get
c - the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) and a static one.

Returns:

the object collection.

getObject

public T getObject(String propertyName, Class c)

Gets an object value.

Parameters:

propertyName - the property to get.
c - the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) and a static one.

Returns:

the object value.

set

public void set(String propertyName, T value)

Sets the value of a property.

Parameters:

propertyName - the property to set.
value - the value of the property.

toObject

public T toObject(Class c)

Converts to an Object (only POJOs and JSONObject are supported).

Parameters:

c - the class of the object, either a POJO class or JSONObject. If c is a POJO class, it must be a member (and not an anonymous or local) and a static one.

Returns:

the POJO.

get

public Object get(String propertyName)

Gets a property value as Object.

Parameters:

propertyName - the property to get.

Returns:

the value of the property.

getBoolean

public Boolean getBoolean(String propertyName)

Gets a boolean value.

Parameters:

propertyName - the property to get.

Returns:

the boolean value.

getCollection

public Collection getCollection(String propertyName)

Gets a JSONObject collection.

Parameters:

propertyName - the property to get.

Returns:

the JSONObject collection.

getDouble

public Double getDouble(String propertyName)

Gets a double value.

Parameters:

propertyName - the property to get.

Returns:

the double value.

getHashMap

public HashMap getHashMap()

Returns the propertybag(JSONObject) in a hashMap

Returns:

the HashMap.

getInt

public Integer getInt(String propertyName)

Gets an integer value.

Parameters:

propertyName - the property to get.

Returns:

the boolean value

getLogger

protected Logger getLogger()

getLong

public Long getLong(String propertyName)

Gets a long value.

Parameters:

propertyName - the property to get.

Returns:

the long value

getMapper

protected ObjectMapper getMapper()

getObject

public JSONObject getObject(String propertyName)

Gets a JSONObject.

Parameters:

propertyName - the property to get.

Returns:

the JSONObject.

getObjectByPath

public Object getObjectByPath(Collection propertyNames)

Gets the value of a property identified by an array of property names that forms the path.

Parameters:

propertyNames - that form the path to the the property to get.

Returns:

the value of the property.

getString

public String getString(String propertyName)

Gets a string value.

Parameters:

propertyName - the property to get.

Returns:

the string value.

has

public boolean has(String propertyName)

Checks whether a property exists.

Parameters:

propertyName - the property to look up.

Returns:

true if the property exists.

remove

public void remove(String propertyName)

Removes a value by propertyName.

Parameters:

propertyName - the property to remove.

toJson

public String toJson()

Converts to a JSON string.

Returns:

the JSON string.

toJson

public String toJson(SerializationFormattingPolicy formattingPolicy)

Converts to a JSON string.

Parameters:

formattingPolicy - the formatting policy instance

Returns:

the JSON string.

toString

public String toString()

Gets Simple String representation of property bag. For proper conversion to json and inclusion of the default values use toJson().

Overrides:

JsonSerializable.toString()

Returns:

string representation of property bag.

toString


public String toString(int indentFactor)

Deprecated

For proper conversion to json and inclusion of the default values use toJson(SerializationFormattingPolicy formattingPolicy).

Gets formatted String representation of property bag.

Parameters:

indentFactor - formatting indentation factor.

Returns:

formatted string representation of property bag.

Applies to