JsonSerializable Class

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

public class JsonSerializable

Represents a base resource that can be serialized to JSON in the Azure Cosmos DB database service.

Constructor Summary

Constructor Description
JsonSerializable()
JsonSerializable(String jsonString)

Constructor.

JsonSerializable(String jsonString, ObjectMapper objectMapper)

Constructor.

Method Summary

Modifier and Type Method and Description
Object get(String propertyName)

Gets a property value as Object.

Boolean getBoolean(String propertyName)

Gets a boolean value.

Collection<ObjectNode> getCollection(String propertyName)

Gets a JSONObject collection.

<T> Collection<T> getCollection(String propertyName, Class<T> c)

Gets an object collection.

Double getDouble(String propertyName)

Gets a double value.

HashMap<String, Object> getHashMap()

Returns the propertybag(JSONObject) in a hashMap

Integer getInt(String propertyName)

Gets an integer value.

<T> List<T> getList(String propertyName, Class<T> c)

Gets an object List.

Logger getLogger()
Long getLong(String propertyName)

Gets a long value.

ObjectMapper getMapper()
ObjectNode getObject(String propertyName)

Gets a JSONObject.

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

Gets an object value.

Object getObjectByPath(List<String> propertyNames)

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

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.

<T> void set(String propertyName, T value)

Sets the value of a property.

String toJson()

Converts to a JSON string.

String toJson(SerializationFormattingPolicy formattingPolicy)

Converts to a JSON string.

<T> T toObject(Class<T> c)

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

String toString()

Gets Simple String representation of property bag.

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

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

Method Details

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.

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.

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

getList

public List getList(String propertyName, Class c)

Gets an object List.

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.

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 ObjectNode getObject(String propertyName)

Gets a JSONObject.

Parameters:

propertyName - the property to get.

Returns:

the JSONObject.

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.

getObjectByPath

public Object getObjectByPath(List 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 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.

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.

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 to be used.

Returns:

the JSON string.

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.

toString

public String toString()

Gets Simple String representation of property bag.

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

Returns:

string representation of property bag.

Applies to